|
4 | 4 | # Copyright 2021 Datadog, Inc. |
5 | 5 |
|
6 | 6 | import json |
7 | | -import os |
8 | | -import boto3 |
9 | 7 | import logging |
10 | | -import requests |
| 8 | +import os |
11 | 9 | from hashlib import sha1 |
12 | 10 |
|
13 | | -from datadog_lambda.wrapper import datadog_lambda_wrapper |
| 11 | +import boto3 |
| 12 | +import requests |
14 | 13 | from datadog import api |
15 | | -from enhanced_lambda_metrics import parse_and_submit_enhanced_metrics |
16 | | -from steps.parsing import parse |
17 | | -from steps.enrichment import enrich |
18 | | -from steps.transformation import transform |
19 | | -from steps.splitting import split |
| 14 | +from datadog_lambda.wrapper import datadog_lambda_wrapper |
| 15 | + |
20 | 16 | from caching.cache_layer import CacheLayer |
| 17 | +from enhanced_lambda_metrics import parse_and_submit_enhanced_metrics |
21 | 18 | from forwarder import Forwarder |
22 | 19 | from settings import ( |
| 20 | + DD_ADDITIONAL_TARGET_LAMBDAS, |
23 | 21 | DD_API_KEY, |
24 | | - DD_SKIP_SSL_VALIDATION, |
25 | 22 | DD_API_URL, |
26 | 23 | DD_FORWARDER_VERSION, |
27 | | - DD_ADDITIONAL_TARGET_LAMBDAS, |
28 | 24 | DD_RETRY_KEYWORD, |
| 25 | + DD_SITE, |
| 26 | + DD_SKIP_SSL_VALIDATION, |
29 | 27 | ) |
| 28 | +from steps.enrichment import enrich |
| 29 | +from steps.parsing import parse |
| 30 | +from steps.splitting import split |
| 31 | +from steps.transformation import transform |
30 | 32 |
|
31 | 33 | logger = logging.getLogger() |
32 | 34 | logger.setLevel(logging.getLevelName(os.environ.get("DD_LOG_LEVEL", "INFO").upper())) |
33 | 35 |
|
34 | 36 | # DD_API_KEY must be set |
35 | 37 | if DD_API_KEY == "<YOUR_DATADOG_API_KEY>" or DD_API_KEY == "": |
36 | | - raise Exception("Missing Datadog API key") |
| 38 | + raise Exception( |
| 39 | + "Missing Datadog API key. Set DD_API_KEY environment variable. " |
| 40 | + "See: https://docs.datadoghq.com/serverless/forwarder/" |
| 41 | + ) |
37 | 42 | # Check if the API key is the correct number of characters |
38 | 43 | if len(DD_API_KEY) != 32: |
39 | 44 | raise Exception( |
40 | | - "The API key is not the expected length. " |
41 | | - "Please confirm that your API key is correct" |
| 45 | + f"Invalid Datadog API key format. Expected 32 characters, received {len(DD_API_KEY)}. " |
| 46 | + f"Verify your API key at https://app.{DD_SITE}/organization-settings/api-keys" |
42 | 47 | ) |
43 | 48 | # Validate the API key |
44 | 49 | logger.debug("Validating the Datadog API key") |
|
57 | 62 | timeout=10, |
58 | 63 | ) |
59 | 64 | if not validation_res.ok: |
60 | | - raise Exception("The API key is not valid.") |
| 65 | + raise Exception( |
| 66 | + f"Datadog API key validation failed (HTTP {validation_res.status_code}). " |
| 67 | + f"Verify your API key is correct and DD_SITE matches your Datadog account region (current: {DD_SITE}). " |
| 68 | + "See: https://docs.datadoghq.com/getting_started/site/" |
| 69 | + ) |
61 | 70 |
|
62 | 71 | # Force the layer to use the exact same API key and host as the forwarder |
63 | 72 | api._api_key = DD_API_KEY |
@@ -106,7 +115,7 @@ def init_cache_layer(function_prefix): |
106 | 115 | if cache_layer is None: |
107 | 116 | cache_layer = CacheLayer(function_prefix) |
108 | 117 | except Exception as e: |
109 | | - logger.exception(f"Failed to create cache layer due to {e}") |
| 118 | + logger.error(f"Failed to create cache layer due to {e}") |
110 | 119 | raise |
111 | 120 |
|
112 | 121 |
|
@@ -135,7 +144,7 @@ def invoke_additional_target_lambdas(event): |
135 | 144 | Payload=lambda_payload, |
136 | 145 | ) |
137 | 146 | except Exception as e: |
138 | | - logger.exception( |
| 147 | + logger.error( |
139 | 148 | f"Failed to invoke additional target lambda {lambda_arn} due to {e}" |
140 | 149 | ) |
141 | 150 |
|
|
0 commit comments