Skip to content

Conversation

@jclusso
Copy link
Contributor

@jclusso jclusso commented Mar 28, 2025

What does this pull request do?

Adds new configuration option so you can set the sampling rate by transaction name. I'm not 100% certain this is the correct way to do this, so please let me know if I should be going about this in a different manner.

{
  transaction_sample_rate_by_name: {
    "UsersController#index": 1.0
    "HealthController#ping": 0
  }
}

Why is it important?

When you have an application with certain portions that get a significant amount of traffic, there is currently no good way to control the sampling. Either you are blind to low volume transactions or have to collect a lot more samples than you need. You can currently get around this with Tail-based sampling, but this is not available on serverless. This also still requires you send a ton of data to your APM server that you may not need to.

Checklist

  • I have signed the Contributor License Agreement.
  • My code follows the style guidelines of this project (See .rubocop.yml)
  • I have rebased my changes on top of the latest main branch
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have made corresponding changes to the documentation
  • I have updated docs/release-notes/index.md
  • I have updated docs/reference/supported-technologies.md
  • Added an API method or config option? Document in which version this will be introduced

Related issues

Resolves #1334

@jclusso jclusso force-pushed the add-transaction-name-sampling-config branch 3 times, most recently from 44add6f to a6e3e78 Compare March 28, 2025 23:41
@jclusso jclusso force-pushed the add-transaction-name-sampling-config branch from a6e3e78 to 5b0fc25 Compare April 20, 2025 02:30
@jclusso
Copy link
Contributor Author

jclusso commented Apr 20, 2025

I have this deployed in production. I thought everything was working until I realized that transactions that are under Requests in Rails seem to have their throughput heavily increased. For Sidekiq related transactions, everything seems fine though.

@estolfo any suggestions?

@jclusso jclusso force-pushed the add-transaction-name-sampling-config branch from 5b0fc25 to 74bc922 Compare April 22, 2025 19:56
@jclusso
Copy link
Contributor Author

jclusso commented Apr 22, 2025

I think I found the issue. I wasn't setting the transaction.sample_rate to be 0 when the transaction wasn't sampled.

@jclusso jclusso force-pushed the add-transaction-name-sampling-config branch from 74bc922 to a88baed Compare May 6, 2025 12:14
@jclusso
Copy link
Contributor Author

jclusso commented May 14, 2025

@estolfo any chance you could give some input on this? This is the only solution for moving to serverless if you rely on tail-based sampling.

@estolfo
Copy link
Contributor

estolfo commented May 14, 2025

Hi @jclusso I'll be able to take a look within the next week. In the meantime, can you please rebase? Tests are passing on main now so they should be reliable for this PR as well.

@jclusso jclusso force-pushed the add-transaction-name-sampling-config branch from a88baed to 54bda9d Compare May 14, 2025 18:37
@jclusso
Copy link
Contributor Author

jclusso commented May 15, 2025

@estolfo i rebased it and the tests seem to be passing if I did everything correctly.

@estolfo
Copy link
Contributor

estolfo commented May 19, 2025

Hi @jclusso thanks for this contribution. I've taken a look but I was wondering if you could explain a bit more what the goals are of this feature. The description says that you'd like to have different sample rates based on transaction name. But the code shows that the span name determines the sample rate on the transaction.
And that the first span on a transaction, if it has a special sample rate, determines the sample rate for the whole transaction.
Would you mind explaining a bit more how you want it to work? thanks!

@jclusso
Copy link
Contributor Author

jclusso commented May 19, 2025

Hi @jclusso thanks for this contribution. I've taken a look but I was wondering if you could explain a bit more what the goals are of this feature.

The goal of the feature is to be able to sample based on transaction name. In Rails this commonly is a controller or worker name.

The description says that you'd like to have different sample rates based on transaction name. But the code shows that the span name determines the sample rate on the transaction. And that the first span on a transaction, if it has a special sample rate, determines the sample rate for the whole transaction. Would you mind explaining a bit more how you want it to work? thanks!

For Rails controllers, the transaction name appears to be set on the first span and the transaction name itself is Rack. Later on it gets set to the first span though. That is why this needs to look at the first span.

@jclusso
Copy link
Contributor Author

jclusso commented May 19, 2025

Might also be worth noting that we're using this in production in two applications since early April. From what we can tell it appears to be working as described in my example config.

@estolfo estolfo self-requested a review May 19, 2025 22:25
@estolfo
Copy link
Contributor

estolfo commented May 21, 2025

run docs-build

@estolfo estolfo merged commit a87a932 into elastic:main May 21, 2025
50 checks passed
@jclusso jclusso deleted the add-transaction-name-sampling-config branch May 29, 2025 13:08
@nywhere
Copy link

nywhere commented Jan 7, 2026

Hello,

This is not available on gem 4.8.0. Is there a way to release it?

Thanks

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to override transaction_sample_rate on a per controller basis

3 participants