Skip to content

Fix use of built-in samplers in SDK configuration#3176

Merged
ocelotl merged 7 commits intoopen-telemetry:mainfrom
matej-g:fix-entrypoint-sampler
Mar 15, 2023
Merged

Fix use of built-in samplers in SDK configuration#3176
ocelotl merged 7 commits intoopen-telemetry:mainfrom
matej-g:fix-entrypoint-sampler

Conversation

@matej-g
Copy link
Copy Markdown
Contributor

@matej-g matej-g commented Feb 15, 2023

Description

Fixes a configuration bug which causes the instrumentation to fall back on the default sampler when a built-in sampler is specified, due to the samplers missing from entry points. For details see description of #3175.

P.S. I'm not a Python developer, so feedback on if this should be done other way is welcome.

Fixes #3175

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@matej-g matej-g changed the title Fix use of in-built samplers in SDK configuration Fix use of built-in samplers in SDK configuration Feb 15, 2023
@matej-g matej-g force-pushed the fix-entrypoint-sampler branch from ca645d4 to 1be89a8 Compare February 15, 2023 15:33
@matej-g matej-g marked this pull request as ready for review February 15, 2023 15:34
@matej-g matej-g requested a review from a team February 15, 2023 15:34
ShauliSolomovich
ShauliSolomovich approved these changes Feb 15, 2023
@matej-g matej-g force-pushed the fix-entrypoint-sampler branch from 51fe90d to 7f0909d Compare February 27, 2023 13:42
@srikanthccv srikanthccv self-assigned this Feb 28, 2023
Copy link
Copy Markdown
Contributor

@ocelotl ocelotl left a comment

Choose a reason for hiding this comment

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

Added a question

matej-g added 2 commits March 10, 2023 16:45
Signed-off-by: Matej Gera <matej.gera@coralogix.com>
Signed-off-by: Matej Gera <matej.gera@coralogix.com>
@matej-g matej-g force-pushed the fix-entrypoint-sampler branch from c9d923f to 1aaad26 Compare March 10, 2023 15:46
Signed-off-by: Matej Gera <matej.gera@coralogix.com>
@matej-g matej-g force-pushed the fix-entrypoint-sampler branch from 1aaad26 to f5b308f Compare March 10, 2023 15:48
@matej-g
Copy link
Copy Markdown
Contributor Author

matej-g commented Mar 10, 2023

Hi @srikanthccv, sorry for the back and forth, I implemented it with your suggestion and cleaned up the PR. Hopefully now all is as should be.

Copy link
Copy Markdown
Member

@srikanthccv srikanthccv left a comment

Choose a reason for hiding this comment

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

Thanks @matej-g , but the type conversion is also missing here

sampler_arg = os.getenv(OTEL_TRACES_SAMPLER_ARG, "")
sampler = sampler_factory(sampler_arg)
This is an existing bug, let me know if you want to make the change in this PR otherwise I will get it fixed separately and then merge this.

It should be changed to

sampler_factory = _import_sampler_factory(sampler_name)

kwargs = {}
if sampler_name in ("traceidratio", "parentbased_traceidratio"):
    try:
        rate = float(os.getenv(OTEL_TRACES_SAMPLER_ARG))
    except ValueError:
        _logger.warning("Could not convert TRACES_SAMPLER_ARG to float.")
        rate = 1.0
    kwargs["rate"] = rate

sampler = sampler_factory(**kwargs)

matej-g added 3 commits March 15, 2023 16:50
Signed-off-by: Matej Gera <matej.gera@coralogix.com>
Signed-off-by: Matej Gera <matej.gera@coralogix.com>
@matej-g matej-g force-pushed the fix-entrypoint-sampler branch from b408173 to fffc0b4 Compare March 15, 2023 16:21
@matej-g
Copy link
Copy Markdown
Contributor Author

matej-g commented Mar 15, 2023

@srikanthccv you're right, that part was still missing. I added your suggestion. Hopefully now everything is fixed as expected.

Copy link
Copy Markdown
Member

@srikanthccv srikanthccv left a comment

Choose a reason for hiding this comment

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

Thank you

@srikanthccv srikanthccv requested a review from ocelotl March 15, 2023 17:29
@ocelotl ocelotl merged commit a70e4a0 into open-telemetry:main Mar 15, 2023
@dnshio
Copy link
Copy Markdown

dnshio commented Mar 16, 2023

Hi. Thanks for this fix. Do you know when this fix will be available on PyPI?

@srikanthccv
Copy link
Copy Markdown
Member

most probably (early) next week based on our monthly release schedule.

@dnshio
Copy link
Copy Markdown

dnshio commented Mar 16, 2023

most probably (early) next week based on our monthly release schedule.

Thanks @srikanthccv 🙌🏽

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.

Setting built-in sampler with auto-instrumentation fails with Failed to initialize custom sampler due to it missing from entry points

6 participants