Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

JacksonWeber
Copy link

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:

  • Added a function _detect_synthetic_user_agent in __init__.py to analyze the User-Agent header and classify requests as either "bot" or "test" traffic, prioritizing test patterns over bot patterns.
  • Set the 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:

  • Introduced a new module semconv.py defining experimental semantic convention constants for synthetic user agent detection, including ATTR_USER_AGENT_SYNTHETIC_TYPE, USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT, and USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST.
  • Updated imports in __init__.py to use these new constants from semconv.py.

Testing:

  • Added a comprehensive test suite in 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.

  • 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?

Tested via unit tests included in test_user_agent_synthetic.py

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

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

@JacksonWeber JacksonWeber requested a review from a team as a code owner August 4, 2025 23:48
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.

2 participants