opentelemetry-ruby-contrib
opentelemetry-ruby-contrib copied to clipboard
feat: add aws Lambda instrumentation
This instrumentation allow user to use the handler to extract parent context from header that produce distributed tracing.
Inspired by splunk ruby lambda layer and opentelemetry python lambda layer. Ruby layer creation can be found in opentelemetry-lambda PR
Sample wrapper should be added in layer creation (with lambda instrumentation).
# wrapper.rb
require 'opentelemetry/sdk'
require 'opentelemetry/exporter/otlp'
require 'opentelemetry/instrumentation/all'
OpenTelemetry::SDK.configure do |c|
c.service_name = '<YOUR_SERVICE_NAME>'
c.use_all() # enables all instrumentation!
end
def otel_wrapper(event:, context:)
otel_wrapper = OpenTelemetry::Instrumentation::AwsLambda::Handler.new()
otel_wrapper.call_wrapped(event: event, context: context)
end
To test with aws lambda, you can try to follow the steps here
@xuan-cao-swi - Are there any tests I should run using both your opentelemetry-lambda PR and this one?
@xuan-cao-swi - Are there any tests I should run using both your opentelemetry-lambda PR and this one?
I will create a detailed step to test lambda-related instrumentation.
@kaylareopelle I have created a gist for the steps; but let me know if it's uncleared or failed.
@xuan-cao-swi, thank you for the gist. It's very helpful! I've done a bit of testing, but wasn't able to successfully get the lambda to appear in New Relic. That might be an issue on our end. I'll also try to run some tests with an open-source endpoint. I plan to resume testing when I return to work on January 2, 2024.
I wasn't able to get the telemetry data into New Relic, but I don't think this needs to be a blocker for the PR. Besides that, everything worked as expected.
Are you using otel default samplers? If that's the case, I need to go back to check if I made some mistakes either in layer side or instrumentation side.
I have added another instruction/result here that I was experimenting with Jaeger on aws lambda instrumentation.
This instrumentation can also help complete the lambda layer build on opentelemetry-lambda
@xuan-cao-swi - I was able to get the lambda instrumentation to work with your updated instructions! 🎉
The key was adding the AWS_LAMBDA_EXEC_WRAPPER=/opt/ruby/otel-handler environment variable.
@xuan-cao-swi While reviewing #887, I noticed you made a few changes to release-please-related files. Do those changes need to be made for the lambda gem as well, or are releases different for this gem?
@xuan-cao-swi While reviewing https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/887, I noticed you made a few changes to release-please-related files. Do those changes need to be made for the lambda gem as well, or are releases different for this gem?
Yes, that would be great if can release together. I have updated the release files.
It looks like we're getting close, @xuan-cao-swi! Is there anything else you were hoping to accomplish before we sync with main and merge this in?
It looks like we're getting close, @xuan-cao-swi! Is there anything else you were hoping to accomplish before we sync with main and merge this in?
Hi @kaylareopelle , no, I think it should be ok. I will open new PR if anything come up (esp. when incorporating with lambda layer build on lambda repo)