You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library will be distributed through JFrog [Bintray](https://bintray.com/beta/#/datadog/datadog-maven/datadog-lambda-java). Follow the [installation instructions](https://docs.datadoghq.com/serverless/installation/java/), and view your function's enhanced metrics, traces and logs in Datadog.
17
+
This library will be distributed through JFrog [Bintray](https://bintray.com/beta/#/datadog/datadog-maven/datadog-lambda-java).
18
+
Follow the [installation instructions](https://docs.datadoghq.com/serverless/installation/java/), and view your function's enhanced metrics, traces and logs in Datadog.
18
19
19
20
## Environment Variables
20
21
@@ -38,191 +39,131 @@ Once [installed](#installation), you should be able to submit custom metrics fro
38
39
39
40
Check out the instructions for [submitting custom metrics from AWS Lambda functions](https://docs.datadoghq.com/integrations/amazon_lambda/?tab=java#custom-metrics).
40
41
41
-
## Distributed Tracing
42
+
## Installing the Java Tracer
42
43
43
-
Wrap your outbound HTTP requests with trace headers to see your lambda in context in APM.
44
-
The Lambda Java Client Library provides instrumented HTTP connection objects as well as helper methods for
45
-
instrumenting HTTP connections made with any of the following libraries:
44
+
The [Java Tracer](https://docs.datadoghq.com/tracing/setup_overview/setup/java/?tab=containers)
45
+
is an optional component that allows you to trace the execution of your Java Lambda function.
46
+
The traces will be viewable from your Serverless function details page within Datadog.
46
47
47
-
- java.net.HttpUrlConnection
48
-
- Apache HTTP Client
49
-
- OKHttp3
48
+
Briefly, in order to use the Java tracer, the following prerquisites must be met (detailed below):
49
+
1. The `datadog-lambda-java` library must be included in your project, following these [installation instructions](https://docs.datadoghq.com/serverless/installation/java/)
50
+
1. You must use a compatible Java runtime
51
+
1. You must attach the Java Tracer lambda layer
52
+
1. Several environment variables must be set
53
+
1. Your handler must instantiate a `new DDLambda` in order to start traces, and call `DDLambda#finish` in order to end traces.
54
+
50
55
51
-
Don't see your favorite client? Open an issue and request it. Datadog is adding to
52
-
this library all the time.
56
+
### Cold start considerations
53
57
54
-
### HttpUrlConnection examples
58
+
The Java Tracer adds a nontrivial cold start penalty.
59
+
Expect roughly 6 seconds per cold start if your Lambda function is configured with 3008MB of memory.
60
+
Lambda runtime CPU scales with the amount of memory allocated, so allocating more memory may help alleviate cold start issues.
61
+
Also consider using provisioned concurrency to keep your lambda function warm.
Alternatively, if you want to do something more complex:
88
+
### Required code modification for the Java Tracer
89
+
90
+
In order to use the Java Tracer, you must instantiate a new `DDLambda` at the beginning of your Lambda function and call `DDLambda#finish()` at the end of it.
`ddl.finish();` finishes the active span and closes the active trace scope.
113
+
The tracer will flush the trace to Cloudwatch logs once this is called.
170
114
171
-
### Trace/Log Correlations
115
+
#Distributed Tracing
172
116
173
-
In order to correlate your traces with your logs, you must inject the trace context
174
-
into your log messages. We've added the these into the slf4j MDC under the key `dd.trace_context`
175
-
and provided convenience methods to get it automatically. The trace context is added to the MDC as a side
176
-
effect of instantiating any `new DDLambda(...)`.
117
+
## Upstream Requests
177
118
178
-
This is an example trace context: `[dd.trace_id=3371139772690049666 dd.span_id=13006875827893840236]`
119
+
You may want to include this Lambda invocation as a child span of some larger trace.
120
+
If so, you should anticipate that the event triggering the Lambda will have some trace context attached to it.
121
+
If this is the case, then you MUST instantiate `DDLambda` with both the request and the lambda context in order for it to extract the trace context.
122
+
E.g. `DDLambda ddl = new DDLambda(request, context);`.
123
+
Currently supported events are:
179
124
180
-
#### JSON Logs
125
+
-`APIGatewayProxyRequestEvent`
126
+
-`APIGatewayV2ProxyRequestEvent`
181
127
182
-
If you are using JSON logs, add the trace ID and span ID to each log message with the keys
183
-
`dd.trace_id` and `dd.span_id` respectively. To get a map containing trace and span IDs,
184
-
call `DDLambda.getTraceContext()`. Union this map with the JSON data being logged.
128
+
If you are using a different event with trace context, you may choose to create a class that implements `Headerable` and supply that as the event instead.
185
129
186
-
#### Plain text logs
130
+
##Downstream Requests
187
131
188
-
If you are using plain text logs, then you must create a new [Parser](https://docs.datadoghq.com/logs/processing/parsing/?tab=matcher)
189
-
by cloning the existing Lambda Pipeline. The new parser can extract the trace context from the correct position in the logs.
190
-
Use the helper `_trace_context`to extract the trace context. For example, if your log line looked like:
132
+
The dd-trace-java tracer will automatically add trace context to outgoing requests for a number of popular services.
133
+
The list of instrumented services can be found here: https://docs.datadoghq.com/tracing/setup_overview/compatibility_requirements/java/ .
134
+
If you wish to enable a beta integration, please note that you must do so using an environment variable.
191
135
192
-
```
193
-
INFO 2020-11-11T14:00:00Z LAMBDA_REQUEST_ID [dd.trace_id=12345 dd.span_id=67890] This is a log message
194
-
```
136
+
# Trace/Log Correlation
195
137
196
-
Then your parser rule would look like:
138
+
Please see [Connecting Java Logs and Traces](https://docs.datadoghq.com/tracing/connect_logs_and_traces/java/?tab=log4j2)
would result in log lines looking like `2020-11-13 19:21:53 [dd.trace_id=1168910694192328743 dd.span_id=3204959397041471598] INFO com.serverless.Handler:20 - Test Log Message`
156
+
Please note that `RequestId` has also been added.
157
+
RequestId is not strictly necessary for Trace/Log correlation, but it is useful for correlating logs and invocations.
217
158
218
-
Just like the **Plain Text Logs** in the previous section, you must create a new [Parser](https://docs.datadoghq.com/logs/processing/parsing/?tab=matcher) in order to parse the trace context correctly.
219
159
160
+
### Grok Parser
220
161
221
-
#### Other logging solutions
162
+
The following grok parser parses Java logs formatted using the pattern in the previous section.
222
163
223
-
If you are using a different logging solution, the trace ID can be accessed using the method
224
-
`DDLambda.getTraceContextString()`. That returns your trace ID as a string that can be added
0 commit comments