Add Support for Detecting Synthetic Source #3674
Open
+299
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.