opentelemetry-ruby-contrib icon indicating copy to clipboard operation
opentelemetry-ruby-contrib copied to clipboard

feat: add aws Lambda instrumentation

Open xuan-cao-swi opened this issue 2 years ago • 7 comments

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 avatar Nov 15 '23 17:11 xuan-cao-swi

@xuan-cao-swi - Are there any tests I should run using both your opentelemetry-lambda PR and this one?

kaylareopelle avatar Dec 08 '23 19:12 kaylareopelle

@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.

xuan-cao-swi avatar Dec 12 '23 19:12 xuan-cao-swi

@kaylareopelle I have created a gist for the steps; but let me know if it's uncleared or failed.

xuan-cao-swi avatar Dec 13 '23 19:12 xuan-cao-swi

@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.

kaylareopelle avatar Dec 22 '23 21:12 kaylareopelle

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.

xuan-cao-swi avatar Jan 19 '24 14:01 xuan-cao-swi

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 avatar Feb 13 '24 19:02 xuan-cao-swi

@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.

kaylareopelle avatar Feb 22 '24 23:02 kaylareopelle

@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?

kaylareopelle avatar May 03 '24 21:05 kaylareopelle

@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.

xuan-cao-swi avatar May 06 '24 15:05 xuan-cao-swi

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?

kaylareopelle avatar May 08 '24 23:05 kaylareopelle

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)

xuan-cao-swi avatar May 10 '24 16:05 xuan-cao-swi