Package: signalfx-lambda-ppiastucki
SignalFx Python Lambda Wrapper.UsageThe SignalFx Python Lambda Wrapper is a wrapper around an AWS Lambda
Python function handler, used to instrument execution of the function
and send metrics and traces to SignalFx.InstallationTo install from PyPipip install signalfx_lambdaConfiguring the ingest endpointBy default, this function wrapper will send to theus0realm. If you are
not in this realm you will need to set theSIGNALFX_INGEST_ENDPOINTenvironment
variable to the correct realm ingest endpoint (https://ingest.{REALM}.signalfx.com).
To determine what realm you are in, check your profile page in the SignalFx
web application (click the avatar in the upper right and click My Profile).Environment VariablesNote: the environment variables ``SIGNALFX_INGEST_ENDPOINT`` and ``SIGNALFX_AUTH_TOKEN`` are being deprecated and will not be supported in future releases.SIGNALFX_ACCESS_TOKEN=accesstoken# endpoint for both metrics and tracer. Overridden by SIGNALFX_METRICS_URL
# and SIGNALFX_TRACING_URL if setSIGNALFX_ENDPOINT_URL=http://<my_gateway>:8080# optional metrics and tracing configurationSIGNALFX_METRICS_URL=ingestendpoint[default:https://pops.signalfx.com]SIGNALFX_SEND_TIMEOUT=timeoutinsecondsforsendingdatapoint[default:0.3]SIGNALFX_TRACING_URL=tracingendpoint[default:https://ingest.signalfx.com/v1/trace]SIGNALFX_ENDPOINT_URLcan be used to configure a common endpoint for metrics and
traces, as is the case when forwarding with the Smart Gateway. The path/v1/tracewill automatically be added to the endpoint for traces.If eitherSIGNALFX_TRACING_URLorSIGNALFX_METRICS_URLare set, they will take
precendence overSIGNALFX_ENDPOINT_URLfor their respective components.For example, if onlySIGNALFX_ENDPOINT_URLis set:SIGNALFX_ENDPOINT_URL=http://<my_gateway>:8080Both metrics and traces will be sent to the gateway address.IfSIGNALFX_ENDPOINT_URLandSIGNALFX_METRICS_URLare set:SIGNALFX_METRICS_URL=https://pops.signalfx.comSIGNALFX_ENDPOINT_URL=http://<my_gateway>:8080Traces will be sent to the gateway and metrics will go through POPS.Wrapping a functionThere are two wrappers provided.For metrics, decorate your handler with @signalfx_lambda.emits_metricsimportsignalfx_lambda@signalfx_lambda.emits_metricsdefhandler(event,context):# your codeFor tracing, use the @signalfx_lambda.is_traced decoratorimportsignalfx_lambda@signalfx_lambda.is_traceddefhandler(event,context):# your codeThe decorators can be used individually or together.Metrics and dimensions sent by the metrics wrapperThe Lambda wrapper sends the following metrics to SignalFx:Metric NameTypeDescriptionfunction.invocationsCounterCount number of
Lambda invocationsfunction.cold_startsCounterCount number of cold
startsfunction.errorsCounterCount number of
errors from
underlying Lambda
handlerfunction.durationGaugeMilliseconds in
execution time of
underlying Lambda
handlerThe Lambda wrapper adds the following dimensions to all data points sent
to SignalFx:DimensionDescriptionlambda_arnARN of the Lambda function
instanceaws_regionAWS Regionaws_account_idAWS Account IDaws_function_nameAWS Function Nameaws_function_versionAWS Function Versionaws_function_qualifierAWS Function Version Qualifier
(version or version alias if it
is not an event source mapping
Lambda invocation)event_source_mappingsAWS Function Name (if it is an
event source mapping Lambda
invocation)aws_execution_envAWS execution environment
(e.g. AWS_Lambda_python3.6)function_wrapper_versionSignalFx function wrapper
qualifier
(e.g. signalfx_lambda_0.0.2)metric_sourceThe literal value of
‘lambda_wrapper’Traces and tags sent by the Tracing wrapperThe tracing wrapper creates a span for the wrapper handler. This span has the following tags:TagDescriptionaws_request_idAWS Request IDlambda_arnARN of the Lambda function
instanceaws_regionAWS Regionaws_account_idAWS Account IDaws_function_nameAWS Function Nameaws_function_versionAWS Function Versionaws_function_qualifierAWS Function Version Qualifier
(version or version alias if it
is not an event source mapping
Lambda invocation)event_source_mappingsAWS Function Name (if it is an
event source mapping Lambda
invocation)aws_execution_envAWS execution environment
(e.g. AWS_Lambda_python3.6)function_wrapper_versionSignalFx function wrapper
qualifier
(e.g. signalfx_lambda_0.0.2)componentThe literal value of
‘python-lambda-wrapper’Sending custom metric from the Lambda functionimportsignalfx_lambda# sending application_performance metric with value 100 and dimension abc:defsignalfx_lambda.send_gauge('application_performance',100,{'abc':'def'})# sending counter metric with no dimensionsignalfx_lambda.send_counter('database_calls',1)Adding manual tracing to the Lambda functionManual instrumentation can be added to trace critical parts of your handler
function.importopentracingtracer=opentracing.tracerdefsome_function():withtracer.start_active_span("span_name",tags=tags)asscope:# do some workspan=scope.spanspan.set_tag("example_tag","example_value")More examples and usage information can be found in the Jaeger Python Tracerdocumentation.Testing it out locallyUse python-lambda-localpip install python-lambda-localpython-lambda-local tests/test.py tests/event.json -a 'arn:aws:lambda:us-east-1:accountId:function:functionNamePython:$LATEST'Packagingpython setup.py bdist_wheel --universalLicenseApache Software License v2. Copyright © 2014-2019 SignalFx