Class DDLambda
- java.lang.Object
-
- com.datadoghq.datadog_lambda_java.DDLambda
-
public class DDLambda extends java.lang.Object
The DDLambda instrumenter is used for getting information about your Lambda into Datadog.
-
-
Constructor Summary
Constructors Modifier Constructor Description DDLambda(com.amazonaws.services.lambda.runtime.Context cxt)
Create a new DDLambda instrumenter given some Lambda contextprotected
DDLambda(com.amazonaws.services.lambda.runtime.Context cxt, java.lang.String xrayTraceInfo)
Testing only: create a DDLambda instrumenter with a given context and xrayTraceInfoDDLambda(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent req, com.amazonaws.services.lambda.runtime.Context cxt)
Create a trace-enabled DDLambda instrumenter given an APIGatewayProxyRequestEvent and a Lambda contextDDLambda(com.amazonaws.services.lambda.runtime.events.APIGatewayV2ProxyRequestEvent req, com.amazonaws.services.lambda.runtime.Context cxt)
Create a trace-enabled DDLambda instrumenter given an APIGatewayV2ProxyEventRequest and a Lambda contextDDLambda(com.amazonaws.services.lambda.runtime.events.KinesisEvent event, com.amazonaws.services.lambda.runtime.Context cxt)
Create a trace-enabled DDLambda instrumenter given an KinesisEvent and a Lambda contextDDLambda(com.amazonaws.services.lambda.runtime.events.SQSEvent event, com.amazonaws.services.lambda.runtime.Context cxt)
Create a trace-enabled DDLambda instrumenter given an SQSEvent and a Lambda contextDDLambda(Headerable req, com.amazonaws.services.lambda.runtime.Context cxt)
Create a trace-enabled DDLambda instrumenter given a custom request object.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.net.URLConnection
addTraceHeaders(java.net.URLConnection urlConnection)
Deprecated.okhttp3.Request
addTraceHeaders(okhttp3.Request request)
Deprecated.org.apache.http.client.methods.HttpUriRequest
addTraceHeaders(org.apache.http.client.methods.HttpUriRequest httpRequest)
Deprecated.protected boolean
checkEnhanced()
protected boolean
checkTraceEnabled()
Check to see if the user has set DD_TRACE_ENABLEDvoid
error(com.amazonaws.services.lambda.runtime.Context cxt)
error increments the aws.lambda.enhanced.error metric in Datadog.void
finish()
Finish the active span.java.util.Map<java.lang.String,java.lang.String>
getTraceContext()
Get the trace context for trace/log correlation.java.lang.String
getTraceContextJSONString()
Get the trace context as a JSON string.java.lang.String
getTraceContextString()
Get the trace context in string form.org.apache.http.client.methods.HttpGet
makeHttpGet(java.lang.String url)
Deprecated.okhttp3.Request.Builder
makeRequestBuilder()
Deprecated.java.net.URLConnection
makeUrlConnection(java.net.URL url)
Deprecated.void
metric(java.lang.String name, double value, java.util.Map<java.lang.String,java.lang.Object> tags)
metric allows the user to record their own custom metric that will be sent to Datadog.void
metric(java.lang.String name, double value, java.util.Map<java.lang.String,java.lang.Object> tags, java.util.Date date)
metric allows the user to record their own custom metric that will be sent to Datadog.protected java.lang.String
santitizeFunctionArn(java.lang.String functionArn)
-
-
-
Constructor Detail
-
DDLambda
public DDLambda(com.amazonaws.services.lambda.runtime.Context cxt)
Create a new DDLambda instrumenter given some Lambda context- Parameters:
cxt
- Enhanced Metrics pulls information from the Lambda context.
-
DDLambda
protected DDLambda(com.amazonaws.services.lambda.runtime.Context cxt, java.lang.String xrayTraceInfo)
Testing only: create a DDLambda instrumenter with a given context and xrayTraceInfo- Parameters:
cxt
- Enhanced Metrics pulls information from the Lambda context.xrayTraceInfo
- This would normally be the contents of the "_X_AMZN_TRACE_ID" env var
-
DDLambda
public DDLambda(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent req, com.amazonaws.services.lambda.runtime.Context cxt)
Create a trace-enabled DDLambda instrumenter given an APIGatewayProxyRequestEvent and a Lambda context- Parameters:
req
- Your Datadog trace headers are pulled from the request and sent to XRay for consumption by the Datadog Xray Crawlercxt
- Enhanced Metrics pulls information from the Lambda context.
-
DDLambda
public DDLambda(com.amazonaws.services.lambda.runtime.events.APIGatewayV2ProxyRequestEvent req, com.amazonaws.services.lambda.runtime.Context cxt)
Create a trace-enabled DDLambda instrumenter given an APIGatewayV2ProxyEventRequest and a Lambda context- Parameters:
req
- Your Datadog trace headers are pulled from the request and sent to XRay for consumption by the Datadog Xray Crawlercxt
- Enhanced Metrics pulls information from the Lambda context.
-
DDLambda
public DDLambda(com.amazonaws.services.lambda.runtime.events.SQSEvent event, com.amazonaws.services.lambda.runtime.Context cxt)
Create a trace-enabled DDLambda instrumenter given an SQSEvent and a Lambda context- Parameters:
event
- Your Datadog trace headers are pulled from the SQS Event and sent to XRay for consumption by the Datadog Xray Crawlercxt
- Enhanced Metrics pulls information from the Lambda context.
-
DDLambda
public DDLambda(com.amazonaws.services.lambda.runtime.events.KinesisEvent event, com.amazonaws.services.lambda.runtime.Context cxt)
Create a trace-enabled DDLambda instrumenter given an KinesisEvent and a Lambda context- Parameters:
event
- Your Datadog trace headers are pulled from the SQS Event and sent to XRay for consumption by the Datadog Xray Crawlercxt
- Enhanced Metrics pulls information from the Lambda context.
-
DDLambda
public DDLambda(Headerable req, com.amazonaws.services.lambda.runtime.Context cxt)
Create a trace-enabled DDLambda instrumenter given a custom request object. Please note that your custom request object MUST implement Headerable.- Parameters:
req
- A custom request object that implements Headerable. Datadog trace headers are pulled from this request object.cxt
- Enhanced Metrics pulls information from the Lambda context.
-
-
Method Detail
-
finish
public void finish()
Finish the active span. If you have installed the dd-trace-java Lambda layer, you MUST call DDLambda.finish() at the end of your Handler in order to finish spans.
-
santitizeFunctionArn
protected java.lang.String santitizeFunctionArn(java.lang.String functionArn)
-
checkEnhanced
protected boolean checkEnhanced()
-
checkTraceEnabled
protected boolean checkTraceEnabled()
Check to see if the user has set DD_TRACE_ENABLED- Returns:
- true if DD_TRACE_ENABLED has been set to "true" (or "TRUE" or "tRuE" or ...), false otherwise
-
metric
public void metric(java.lang.String name, double value, java.util.Map<java.lang.String,java.lang.Object> tags)
metric allows the user to record their own custom metric that will be sent to Datadog.- Parameters:
name
- The metric's namevalue
- The metric's valuetags
- A map of tags to be assigned to the metric
-
metric
public void metric(java.lang.String name, double value, java.util.Map<java.lang.String,java.lang.Object> tags, java.util.Date date)
metric allows the user to record their own custom metric that will be sent to Datadog. also allows user to set his/her own date.- Parameters:
name
- The metric's namevalue
- The metric's valuetags
- A map of tags to be assigned to the metricdate
- The date under which the metric value will appear in datadog
-
error
public void error(com.amazonaws.services.lambda.runtime.Context cxt)
error increments the aws.lambda.enhanced.error metric in Datadog.- Parameters:
cxt
- The AWS Context provided to your handler
-
makeUrlConnection
@Deprecated public java.net.URLConnection makeUrlConnection(java.net.URL url) throws java.io.IOException
Deprecated.Installing dd-java-agent in your lambda environment automatically wraps outbound HTTP calls. This is no longer necessary.openConnection calls openConnection on the provided URL, adds the Datadog trace headers, and then returns the resulting URLConnection. This duplicates the usual workflow with a java.net.URLConnection
- Parameters:
url
- the URL to which you want to open a connection.- Returns:
- a newly opened URLConnection with Datadog trace headers.
- Throws:
java.io.IOException
-
addTraceHeaders
@Deprecated public java.net.URLConnection addTraceHeaders(java.net.URLConnection urlConnection)
Deprecated.Installing dd-java-agent in your lambda environment automatically wraps outbound HTTP calls. This is no longer necessary.Adds Datadog trace headers to a java.net.URLConnection, so you can trace downstream HTTP requests.
- Parameters:
urlConnection
- the URLConnection that will have the trace headers added to it.- Returns:
- Returns a mutated URLConnection with the new trace headers.
-
makeHttpGet
@Deprecated public org.apache.http.client.methods.HttpGet makeHttpGet(java.lang.String url)
Deprecated.Installing dd-java-agent in your lambda environment automatically wraps outbound HTTP calls. This is no longer necessary.Creates an Apache HttpGet instrumented with Datadog trace headers. Please note, this does not _execute_ the HttpGet, it merely creates a default HttpGet with headers added.
- Parameters:
url
- The URL that will eventually be gotten.- Returns:
- Returns an HttpGet for the provided URL, instrumented with Datadog trace headers.
-
addTraceHeaders
@Deprecated public org.apache.http.client.methods.HttpUriRequest addTraceHeaders(org.apache.http.client.methods.HttpUriRequest httpRequest)
Deprecated.Installing dd-java-agent in your lambda environment automatically wraps outbound HTTP calls. This is no longer necessary.Adds Datadog trace header to an org.apache.http.client.methods.HttpUriRequest, so you can trace downstream HTTP requests.
- Parameters:
httpRequest
- the HttpUriRequest that will have the trace headers added to it.- Returns:
- Returns a mutated HttpUriRequest with the new trace headers.
-
makeRequestBuilder
@Deprecated public okhttp3.Request.Builder makeRequestBuilder()
Deprecated.Installing dd-java-agent in your lambda environment automatically wraps outbound HTTP calls. This is no longer necessary.Create an OKHttp3 request builder with Datadog headers already added.
- Returns:
- Returns an OKHttp3 Request Builder with Datadog trace headers already added.
-
addTraceHeaders
@Deprecated public okhttp3.Request addTraceHeaders(okhttp3.Request request)
Deprecated.Installing dd-java-agent in your lambda environment automatically wraps outbound HTTP calls. This is no longer necessary.Adds Datadog trace header to an OKHttp3 request, so you can trace downstream HTTP requests.
- Parameters:
request
- The OKHttp3 Request that will have the trace headers added to it.- Returns:
- Returns a mutated OKHttp3 Request with the new trace headers.
-
getTraceContext
public java.util.Map<java.lang.String,java.lang.String> getTraceContext()
Get the trace context for trace/log correlation. This is optional, as dd.trace_id and dd.span_id are automatically injected into the MDC.- Returns:
- a map of the current trace context
-
getTraceContextString
public java.lang.String getTraceContextString()
Get the trace context in string form. Inject this into your logs in order to correlate logs with traces.- Returns:
- a string representation of the current trace context
-
getTraceContextJSONString
public java.lang.String getTraceContextJSONString()
Get the trace context as a JSON string. This can be used to inject tracing context into message queues. SQS Example:class X { // ... public void sendMessageToSQS(DDLambda ddl) { SendMessageRequest sendMessageRequest = new SendMessageRequest() .withQueueUrl("somewhere") .withMessageBody("foobar") .withMessageAttributes(Map.of( SQSHeaderable.DATADOG_ATTRIBUTE_NAME, new MessageAttributeValue().withStringValue(ddLambda.getTraceContextJSONString()) )); sqs.sendMessage(sendMessageRequest); } }
- Returns:
- a JSON string representation of the current trace context. Empty string if tracing IDs are not found.
-
-