ℹ️ SignalFx was acquired by Splunk in October 2019. See Splunk SignalFx for more information.
The SignalFx Java Lambda Wrapper has reached end of life and has been permanently archived.
The Splunk OpenTelemetry Lambda Layer is the successor. To learn how to migrate, see the supporting documentation
- Java 8+
You can use this document to add a SignalFx wrapper to your AWS Lambda for Java, specifically for Java 8+.
The SignalFx Java Lambda Wrapper wraps around an AWS Lambda Java function handler, which allows metrics to be sent to SignalFx.
<dependency>
<groupId>com.signalfx.public</groupId>
<artifactId>signalfx-lambda</artifactId>
<version>0.1.1</version>
</dependency>
There are two ways to wrap the function. You can use the SignalFx handler or manually wrap the function.
-
Configure the AWS function handler to have one of the following values:
- Use
com.signalfx.lambda.wrapper.SignalFxRequestWrapper::handleRequest
for normal input/output request.- To review an example, please see CustomRequestHandler.java.
- Use
com.signalfx.lambda.wrapper.SignalFxRequestStreamWrapper::handleRequest
for normal stream request.- To review an example, please see CustomRequestHandler.java. To review additional custom function signatures, please see lambda-java examples.
- Use
-
Use the
SIGNALFX_LAMBDA_HANDLER
environment variable to set the handler function. The format of the handler needs to bepackage.ClassName::methodName
, such ascom.signalfx.lambda.example.CustomHandler::handler
.Review the following example:
SIGNALFX_LAMBDA_HANDLER=com.signalfx.lambda.example.CustomHandler::handler
-
To learn how to manually wrap a function, review the following example:
// in your handler MetricWrapper wrapper = new MetricWrapper(context) try { // your code } catch (Exception e) { wrapper.error(); } finally { wrapper.close(); }
For more examples, please see CustomHandler.java.
-
Configure the handler for the function in AWS to point to the main method in your code. The handler needs to be in the
package.ClassName::methodName
format.
- Package the .jar file, and then upload to AWS.
- To learn how to upload, please see the instructions from AWS.
By default, this function wrapper will send data to the us0 realm. As a result, if you are not in us0 realm and you want to use the ingest endpoint directly, then you must explicitly set your realm. To set your realm, use a subdomain, such as ingest.us1.signalfx.com or ingest.eu0.signalfx.com.
To locate your realm:
- Open SignalFx and in the top, right corner, click your profile icon.
- Click My Profile.
- Next to Organizations, review the listed realm.
To set your realm, you will need to use a subdomain, such as ingest.us1.signalfx.com or ingest.eu0.signalfx.com. This action will be explained in Step 5.
Set the Lambda environment variables as follows:
- Set authentication token:
SIGNALFX_AUTH_TOKEN=signalfx token
- (Optional) Set additional parameters:
SIGNALFX_API_HOSTNAME=[ingest.us0.signalfx.com] SIGNALFX_API_PORT=[443] SIGNALFX_API_SCHEME=[https] SIGNALFX_SEND_TIMEOUT=milliseconds for signalfx client timeout [2000]
If your SignalFx account is not in the us0 realm, SIGNALFX_API_HOSTNAME
should be set to ingest endpoint, which you located in Step 4.
- To send custom metrics, review the following example.
// construct data point builder
SignalFxProtocolBuffers.DataPoint.Builder builder =
SignalFxProtocolBuffers.DataPoint.newBuilder()
.setMetric("application.metric")
.setMetricType(SignalFxProtocolBuffers.MetricType.GAUGE)
.setValue(
SignalFxProtocolBuffers.Datum.newBuilder()
.setDoubleValue(100));
// add custom dimension
builder.addDimensionsBuilder().setKey("applicationName").setValue("CoolApp").build();
// send the metric
MetricSender.sendMetric(builder);
For advanced users who want to reduce the size of deployment packages, please visit the AWS documentation site and see AWS Lambda Layers.
At a high level, to reduce the size of deployments with AWS Lambda layers, you must:
- Determine the layer to use. There are two options:
- Option 1: Layer hosted by SignalFx
- You can use the version of the layer hosted by SignalFx. Available hosted layers may differ based on region. To review the latest available version based on your region, please see the list of supported versions.
- Option 2: SAM (Serverless Application Model) template
- You can deploy a copy of the SignalFx-provided layer to your account. SignalFx provides a SAM template that will create a layer with the wrapper in your AWS account.
- To use this option, log into your AWS account. In the Lambda section, create a function, and then choose the option to create a function from a template. Search for SignalFx, choose Java, and then deploy.
- You can also locate the SignalFx layer using the Serverless Application Repository service.
- Option 1: Layer hosted by SignalFx
- Verify that dependencies included in the layer are not included in the Lambda .jar file.
- Attach the layer to the Lambda function.
Based on your build and deployment system, there are various ways to complete Step 2 and Step 3. In general, to not include the wrapper in your .jar file, you can mark the dependency as having provided
scope.
The Lambda wrapper sends the following metrics to SignalFx:
Metric Name | Type | Description |
---|---|---|
function.invocations | Counter | Count number of Lambda invocations |
function.cold_starts | Counter | Count number of cold starts |
function.errors | Counter | Count number of errors from underlying Lambda handler |
function.duration | Gauge | Milliseconds in execution time of underlying Lambda handler |
The Lambda wrapper adds the following dimensions to all data points sent to SignalFx:
Dimension | Description |
---|---|
lambda_arn | ARN of the Lambda function instance |
aws_region | AWS Region |
aws_account_id | AWS Account ID |
aws_function_name | AWS Function Name |
aws_function_version | AWS Function Version |
aws_function_qualifier | AWS Function Version Qualifier (version or version alias if it is not an event source mapping Lambda invocation) |
event_source_mappings | AWS Function Name (if it is an event source mapping Lambda invocation) |
aws_execution_env | AWS execution environment (e.g. AWS_Lambda_java8) |
function_wrapper_version | SignalFx function wrapper qualifier (e.g. signalfx-lambda-0.0.5) |
metric_source | The literal value of 'lambda_wrapper' |
- A test example is available at
com.signalfx.lambda.example.CustomHandler::handler
. If necessary, make desired changes.
- Set test input event and Lambda function handler. Review the following example.
LAMBDA_INPUT_EVENT='{"abc": "def"}' LAMBDA_RUNNER_HANDLER=com.signalfx.lambda.wrapper.SignalFxRequestWrapper SIGNALFX_LAMBDA_HANDLER=com.signalfx.lambda.example.CustomHandler::handler
- Run
mvn compile exec:java
.
-
Run
mvn clean compile package -Ptest
to package using the test profile, which will include the runner and test handler. -
Set the SignalFx Lambda handler environment variable to either
com.signalfx.lambda.example.CustomHandler::handler
orcom.signalfx.lambda.example.CustomStreamHandler::handleRequest
.
Apache Software License v2. Copyright © 2014-2020 Splunk