ℹ️ SignalFx was acquired by Splunk in October 2019. See Splunk SignalFx for more information.
The Splunk Ruby 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
SignalFx Ruby Lambda WrapperYou can use this document to add a SignalFx wrapper to your AWS Lambda for Ruby.
The SignalFx Ruby Lambda Wrapper wraps around an AWS Lambda Ruby function handler, which allows metrics and traces to be sent to SignalFx.
At a high-level, to add a SignalFx Ruby Lambda wrapper, you can package the code yourself, or you can use a Lambda layer containing the wrapper and then attach the layer to a Lambda function.
To learn more about Lambda layers, please visit the AWS documentation site and see AWS Lambda Layers.
Step 1: Add the Lambda wrapper in AWSTo add the SignalFx wrapper, you have the following options:
In this option, you will use a Lambda layer created and hosted by SignalFx.
In this option, you will choose a SignalFx template, and then deploy a copy of the layer.
$ bundle install --path vendor/bundle
By default, this function wrapper will send data to the us0 realm. As a result, if you are not in the us0 realm and you want to use the ingest endpoint directly, then you must explicitly set your realm.
To locate your realm:
To set your realm, when configuring variables, make sure to use a subdomain, such as ingest.us1.signalfx.com or ingest.eu0.signalfx.com. This action will take place in Step 3.
Step 3: Set environment variablesSet SIGNALFX_ACCESS_TOKEN with your correct access token. (If you are using Smart Gateway for both metrics and traces, then you can skip this step.) Review the following example.
SIGNALFX_ACCESS_TOKEN=access token
If you use Smart Gateway, or want to ingest directly from a realm other than us0, then you must set at least one endpoint variable. (For environment variables, SignalFx defaults to the us0 realm. As a result, if you are not in the us0 realm, you may need to set your environment variables.) There are two options:
SIGNALFX_ENDPOINT_URL
where both metrics and traces will be sent to the gateway address. Note that the path /v1/trace
will be automatically added to the endpoint for traces. Review the following example.SIGNALFX_ENDPOINT_URL=http://<my_gateway>:8080
SIGNALFX_ENDPOINT_URL
to send traces to the gateway and SIGNALFX_METRICS_URL
to send metrics directly. Review the following example.SIGNALFX_METRICS_URL=https://ingest.signalfx.com SIGNALFX_ENDPOINT_URL=http://<my_gateway>:8080
By default, SIGNALFX_METRICS_URL
points to the us0
realm. If you are not in this realm, you must use the correct subdomain (https://ingest.{REALM}.signalfx.com), as stated in Step 2.
(Optional) Specify an operation timeout (in seconds) with the SIGNALFX_SEND_TIMEOUT
environment variable. The default value is 1 second. Review the following example.
(Optional) Set additional environment variables for tracer configuration. Review the following examples.
SIGNALFX_SERVICE_NAME SIGNALFX_TRACING_URL=tracing endpoint [ default: https://ingest.signalfx.com/v1/trace ]
For SIGNALFX_TRACING_URL
:
SIGNALFX_TRACING_URL
should point to your Smart Gateway. In this situation, an access token is not needed.SIGNALFX_TRACING_URL
does not point to your Smart Gateway, then the tracing URL defaults to https://ingest.signalfx.com/v1/trace
. In this situation, an access token is required.SIGNALFX_TRACING_URL
points to the us0
realm. If you are not in this realm, then you must use the correct subdomain (https://ingest.{REALM}.signalfx.com), as stated in Step 2.To learn more, see:
require 'signalfx/lambda'
To use the wrapper, put source.SignalFx::Lambda.wrapped_handler
as the handler in the AWS console where source
is your Ruby source file.
source
is lambda_function
. A complete handler value is lambda_function.SignalFx::Lambda.wrapped_handler
.In a space after your handler function definition, register the function to be automatically traced. Review the following example.
# this is the original handler def handler(event:, context:) JSON.generate(body) end SignalFx::Lambda.register_handler(metrics: true, tracing: true, &method(:handler))
register_handler
will accept any block.metrics
: Enable reporting of metrics. Default: true
tracing
: Enable tracing. Default: true
SignalFx::Lambda::Metrics.client.send(counters: ..., gauges: ..., cumulative_counters: ...)(Optional) Step 6: Add manual tracing
You can add manual tracing to get a deeper view of the function. The OpenTracing global tracer makes the tracer used by the wrapper available when you want more specific instrumentation. Review the following example.
require 'opentracing' OpenTracing.global_tracer.start_active_span("span_name") do |scope| work_to_be_traced end
These manually created spans will automatically be nested, with the span for the Lambda handler as the parent. For more examples, please see opentracing-ruby.
Metrics and dimensions sent by the metrics wrapperWhen metrics are enabled, the following datapoints are sent to SignalFx:
Metric Name Type Descriptionfunction.invocations
Counter Count number of Lambda invocations function.cold_starts
Counter Count number of cold starts function.errors
Counter Count number of errors captured from underlying Lambda handler function.duration
Gauge Execution time of the underlying Lambda handler in milliseconds
Each datapoint has the following dimensions:
metric_source
: ruby-lambda-wrapper
lambda_arn
: the full ARN of the invocationaws_region
: the region that the function executed inaws_account_id
: id of the account this function ran foraws_function_name
: the function name set for this Lambdaaws_function_version
: the function versionaws_function_qualifier
: function version qualifier, which will be a version or version alias if it is not an event source mapping invocationevent_source_mappings
: function name if it is an event source mapping invocationaws_execution_env
: the name of the runtime environment running this functionfunction_wrapper_version
: the version of this wrapper gem being usedlog_group_name
: log group for the functionlog_stream_name
: log stream for the instanceThe wrapper will generate a trace per function invocation. The parent span will be named with the pattern lambda_ruby_<function_name>
. The span prefix can be optionally configured with the SIGNALFX_SPAN_PREFIX
environment variable. Review the following example.
$ SIGNALFX_SPAN_PREFIX=custom_prefix_
This configuration will make spans have the name custom_prefix_<function_name>
Each span will also have the following tags:
component
: ruby-lambda-wrapper
lambda_arn
: the full ARN of the invocationaws_request_id
: the identifier of the invocation requestaws_region
: the region that the function executed inaws_account_id
: id of the account this function ran foraws_function_name
: the function name set for this Lambdaaws_function_version
: the function versionaws_execution_env
: the name of the runtime environment running this functionlog_group_name
: log group for the functionlog_stream_name
: log stream for the instancefunction_wrapper_version
: the version of this wrapper gem being usedIf a qualifier
is present in the ARN, depending on the resource type, either aws_function_qualifier
or event_source_mappings
will be tagged.
After you check out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
.
To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version. Then, push git commits and tags, and then push the .gem
file to rubygems.org.
You can send bug reports and pull requests through GitHub at https://github.com/signalfx/lambda-ruby.
The gem is available as open source under the terms of the Apache 2.0 License.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4