-
Notifications
You must be signed in to change notification settings - Fork 768
Add Support for Detecting Synthetic Source #3674
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
base: main
Are you sure you want to change the base?
Add Support for Detecting Synthetic Source #3674
Conversation
...pentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py
Outdated
Show resolved
Hide resolved
instrumentation/opentelemetry-instrumentation-requests/tests/test_user_agent_synthetic.py
Show resolved
Hide resolved
...pentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there's nothing requests specific here I think this should go into opentelemetry-util-http
instead. Said that I'm not sure we should ship our own experimental semantic conventions. I don't see any PR in the semantic-conventions repo adding this stuff, so could you please elaborate a bit what's your plan?
So I had seen this PR in semconv repo open-telemetry/semantic-conventions#1523 before writing that comment but I only read the PR description with an old attribute name and not the title with the updated one that matches this. So since we already have the attribute in the semconv since a few (https://github.com/open-telemetry/opentelemetry-python/blob/05343a5c8848f5f55a69100a0becf61766b33051/opentelemetry-semantic-conventions/src/opentelemetry/semconv/_incubating/attributes/user_agent_attributes.py#L41) we should just import it from there and not opencode it. |
|
Thanks for the point out here, the guidance in OTel JS works a bit differently (they ask to hard-code these kinds of experimental semantic conventions in order to avoid breaking customers using the old experimental attributes). I'll update these imports. |
Description
This pull request introduces experimental support for detecting synthetic traffic (such as bots and test monitors) in the OpenTelemetry Requests instrumentation by analyzing the
User-Agent
header. It adds logic to classify requests as originating from bots or test systems, sets a corresponding span attribute, and includes comprehensive tests to validate this behavior.The most important changes are:
Synthetic User Agent Detection and Span Attributes:
_detect_synthetic_user_agent
in__init__.py
to analyze theUser-Agent
header and classify requests as either "bot" or "test" traffic, prioritizing test patterns over bot patterns.user_agent.synthetic.type
span attribute when a synthetic user agent is detected, using new constants for attribute name and possible values. [1] [2]Semantic Conventions:
semconv.py
defining experimental semantic convention constants for synthetic user agent detection, includingATTR_USER_AGENT_SYNTHETIC_TYPE
,USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT
, andUSER_AGENT_SYNTHETIC_TYPE_VALUE_TEST
.__init__.py
to use these new constants fromsemconv.py
.Testing:
test_user_agent_synthetic.py
to verify detection logic for various user agent scenarios, including bots, test agents, normal browsers, case insensitivity, substring matches, and pattern priority.Please delete options that are not relevant.
How Has This Been Tested?
Tested via unit tests included in
test_user_agent_synthetic.py
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.