Releases: signalfx/lambda-python
v1.0.0 beta 5
Features
- Now tracer is initialized only once on cold boot and flushed before each request finishes. This should make each warm invocation a little but more faster.
- Added support for auto instrumentation. Supported libraries will be automatically instrumented provided their instrumentation packages are installed as well.
1.0.0b2
Features
Propagating trace context to outgoing requests or lambda response
The library ships a helper function to inject tracing context headers into a dictionary like object. The function accepts two arguments. First argument must be a dictionary like object that the trace context is injected into. The second argument is optional and must be a OpenTracing span context. If one is not provided, the function uses the currently active span. Example:
Before
import signalfx_lambda
@signalfx_lambda.is_traced()
def handler(event, context):
request = urllib.request.Request('http://some-service', headers={...})
response = urllib.request.urlopen(request)
# handle response
After
import signalfx_lambda
@signalfx_lambda.is_traced()
def handler(event, context):
headers = {...}
# inject trace context into the headers dictionary
signalfx_lambda.tracing.inject(headers)
request = urllib.request.Request('http://some-service', headers=headers)
response = urllib.request.urlopen(request)
# handle response
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