Skip to content

Conversation

@joshwestbrook
Copy link
Contributor

@joshwestbrook joshwestbrook commented Dec 18, 2024

Our company uses container images for deploying our lambda functions and use herokuish Procfile entries as our entrypoints for the images.

This means it takes a ton of jiggery-pokery to get this working for our situation because:

  1. We can't natively pull in a lambda layer without using the AWS S3 CLI to pull down the layer zip and copy into our base image
  2. The _HANDLER environment variable actually contains our Procfile entry (which calls the lambda RIC under the hood with the handler that's expected by this wrapper)

This PR introduces an alternative way of instrumenting by programmatically wrapping an arbitrary handler method for scenarios where using lambda layers aren't an option (such as ours).

Example:

require 'opentelemetry/instrumentation/aws_lambda'

module Example
  class Handler
    extend OpenTelemetry::Instrumentation::AwsLambda::Wrap

    def self.process(event:, context:)
      pp event
    end
    instrument_handler :process
  end
end

@arielvalentin
Copy link
Contributor

cc: @jterapin @alextwoods @NathanielRN

Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @joshwestbrook! It's great to see the lambda instrumentation getting some use and I like your adjustment to make it more flexible for different scenarios.

Since @xuan-cao-swi initially wrote this, I'd like him to also take a look before we merge.

@joshwestbrook
Copy link
Contributor Author

Thanks, @joshwestbrook! It's great to see the lambda instrumentation getting some use and I like your adjustment to make it more flexible for different scenarios.

Since @xuan-cao-swi initially wrote this, I'd like him to also take a look before we merge.

Awesome, thanks for taking a look at this @kaylareopelle!

@xuan-cao-swi
Copy link
Contributor

Thanks @joshwestbrook , I think it looks good. Would you mind add some test case around the instrument_handler function.

@joshwestbrook joshwestbrook force-pushed the aws_lambda-programatic-wrap branch from fc01a58 to c5994bc Compare January 27, 2025 15:35
@joshwestbrook
Copy link
Contributor Author

joshwestbrook commented Jan 27, 2025

Thanks @joshwestbrook , I think it looks good. Would you mind add some test case around the instrument_handler function.

Sure thing @xuan-cao-swi! I pushed up some tests for the instrument_handler method in c5994bc

I'm very used to using RSpec for specs so let me know if you have any recommendations for improvements 😄

@xuan-cao-swi
Copy link
Contributor

Hi @joshwestbrook , just need linting from rubocop, then I can approve it.

@kaylareopelle
Copy link
Contributor

@xuan-cao-swi - Rubocop linting has passed now! Can you take another look?

@kaylareopelle kaylareopelle enabled auto-merge (squash) January 29, 2025 20:03
@kaylareopelle kaylareopelle merged commit fb9cdf4 into open-telemetry:main Jan 29, 2025
59 checks passed
@github-actions github-actions bot mentioned this pull request Jan 29, 2025
akahn added a commit to akahn/opentelemetry-ruby-contrib that referenced this pull request Jan 29, 2025
…metry-ruby-contrib into strip-rails-format-suffix

* 'strip-rails-format-suffix' of github.com:akahn/opentelemetry-ruby-contrib:
  feat: AWS lambda programatic wrap (open-telemetry#1308)
  chore: bump ruby/setup-ruby from 1.213.0 to 1.214.0 (open-telemetry#1371)
  test: Fix simplecov configuration (open-telemetry#1366)
  chore: Strip Rails (.:format) suffix from http.route
akahn pushed a commit to akahn/opentelemetry-ruby-contrib that referenced this pull request Jan 30, 2025
* feat: Support programatically wrapping lambda handlers

* chore: Update README and conditionally flush metrics

* fix: No ruby 3.1 shorthand

* fix: typo and module length

* Add tests for instrument_handler

* fix: Trailing whitespace

---------

Co-authored-by: Kayla Reopelle <[email protected]>
@joshwestbrook
Copy link
Contributor Author

Hey @kaylareopelle @xuan-cao-swi! Do y'all have any estimate on when we could expect to see this functionality released?

We're eager to start using this in production and would prefer to be pointed at a released version if possible so that we are covered by our vulnerability scanning tools 😄

@kaylareopelle
Copy link
Contributor

Hi @joshwestbrook, we should release tomorrow!

@kaylareopelle
Copy link
Contributor

Hi @joshwestbrook! This code has been released! You can find it in:

  • opentelemetry-instrumentation-aws_lambda 0.3.0
  • opentelemetry-instrumentation-all 0.73.0

@joshwestbrook
Copy link
Contributor Author

Excellent, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants