v1.0.0b1
Breaking changes
- The wrappers (wrapper, emit_metrics, is_traced) are now functions that return decorators.
- This means they must now be called as functions explicitly.
Upgrading to 1.0.0beta1
Given you have a lambda function that looks like the following:
import json
import signalfx_lambda
@signalfx_lambda.is_traced
def lambda_handler(event, context):
...
Then you must change line 4 so that @signalfx_lambda.is_traced
is now invoked as a function as follows
import json
import signalfx_lambda
@signalfx_lambda.is_traced()
def lambda_handler(event, context):
...
Features
Context propagation
The wrapper not tries to automatically extract B3 tracing headers from the event
object and use the extracted span context as the parent span when generating the span for the lambda invocation. The wrapper tries to extract the B3 headers from headers
or attributes
dictionary if found in the event
object.
Helper to create manual span
The wrapper now ships with a create_span
context manager that makes it very easy to create spans from a lambda invocation context. Example:
import json
import signalfx_lambda
@signalfx_lambda.is_traced(with_span=False)
def lambda_handler(event, context):
with signalfx_lambda.create_span(event, context):
# lambda code
This will create a new span, add lambda metadata as span attributes and try to extract any tracing context from the event object if present, and use it as the parent span.
- You can disable adding lambda metadata to the span as attributes by passing
auto_add_tags=False
. - You can explicitly pass an operation name for the span by passing
operation_name=<custom_op_name>
.
Disable automatic span generation
is_traced
function now takes a single boolean argument called with_span
which defaults to True
. You can set it to False
in order to disable automatic span generation. This is useful when you want to initialize the tracing machinery but want to generate all the spans manually on your own. One scenario where this is useful is when processing SQS messages. Since a lambda usually receives multiple SQS messages in a single invocation, we'd usually want to link each operation to process an individual message with the span generated by the producer that produced the message.
Example SQS processing
import json
import signalfx_lambda
@signalfx_lambda.is_traced(with_span=False)
def lambda_handler(event, context):
for record in event.get('Records', []):
with signalfx_lambda.create_span(record, context):
# code to process record