-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Update tracing hook for semantic convention updates. #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fe88bc8
4eb28ab
a24943a
af580ed
581417f
7c3b886
16a50b7
f4c598b
51ec399
f5c3178
c2d463a
6942880
1fb4d78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| import json | ||
| import warnings | ||
| from dataclasses import dataclass | ||
|
|
||
| from ldclient.evaluation import EvaluationDetail | ||
|
|
@@ -25,13 +27,29 @@ class HookOptions: | |
| """ | ||
| If set to true, then the tracing hook will add the evaluated flag value to | ||
| span events. | ||
|
|
||
| .. deprecated:: 1.0.0 | ||
| This option is deprecated and will be removed in a future version. | ||
| Use :attr:`include_value` instead. | ||
| """ | ||
|
|
||
| include_value: bool = False | ||
| """ | ||
| If set to true, then the tracing hook will add the evaluated flag value to | ||
| span events. | ||
| """ | ||
|
|
||
|
|
||
| class Hook(LDHook): | ||
| def __init__(self, options: HookOptions = HookOptions()): | ||
| self.__tracer = trace.get_tracer_provider().get_tracer("launchdarkly") | ||
| self.__options = options | ||
| if self.__options.include_variant: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know an actually reasonable way to do this without the logger instance.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just grab the logger from wherever. Python is just like that. from logging import getLogger
logger = getLogger('launchdarkly-otel')
logger.warning('Hi there')If we document that we always use the 'launchdarkly-otel' named logger, then it makes it easy for customers to affect the formatting without having to pass a logger around everywhere. But this honestly seems pretty reasonable to me. |
||
| warnings.warn( | ||
| "The 'include_variant' option is deprecated and will be removed in a future version. " | ||
| "Use 'include_value' instead.", | ||
| DeprecationWarning, | ||
| ) | ||
|
|
||
| @property | ||
| def metadata(self) -> Metadata: | ||
|
|
@@ -56,7 +74,7 @@ def before_evaluation(self, series_context: EvaluationSeriesContext, data: dict) | |
| return data | ||
|
|
||
| attributes = { | ||
| 'feature_flag.context.key': series_context.context.fully_qualified_key, | ||
| 'feature_flag.context.id': series_context.context.fully_qualified_key, | ||
| 'feature_flag.key': series_context.key, | ||
| } | ||
|
|
||
|
|
@@ -88,13 +106,19 @@ def after_evaluation(self, series_context: EvaluationSeriesContext, data: dict, | |
| return data | ||
|
|
||
| attributes = { | ||
| 'feature_flag.context.key': series_context.context.fully_qualified_key, | ||
| 'feature_flag.context.id': series_context.context.fully_qualified_key, | ||
| 'feature_flag.key': series_context.key, | ||
| 'feature_flag.provider_name': 'LaunchDarkly' | ||
| 'feature_flag.provider.name': 'LaunchDarkly', | ||
| } | ||
|
|
||
| if self.__options.include_variant: | ||
| attributes['feature_flag.variant'] = str(detail.value) | ||
| if detail.variation_index is not None: | ||
| attributes['feature_flag.result.variationIndex'] = str(detail.variation_index) | ||
|
|
||
| if detail.reason.get('inExperiment'): | ||
| attributes['feature_flag.result.reason.inExperiment'] = 'true' | ||
|
|
||
| if self.__options.include_value or self.__options.include_variant: | ||
| attributes['feature_flag.result.value'] = json.dumps(detail.value) | ||
|
|
||
| span.add_event('feature_flag', attributes=attributes) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.