Skip to content

feat: add optional operation_name to function_trace/create_span - #553

Merged
robrap merged 1 commit into
openedx:masterfrom
rahulkanneri-2u:rahul/add-operation-name-to-create-span
Oct 1, 2026
Merged

robrap merged 1 commit into
openedx:masterfrom
rahulkanneri-2u:rahul/add-operation-name-to-create-span

Conversation

@rahulkanneri-2u

Copy link
Copy Markdown
Contributor

Description:

Adds an optional operation_name argument to function_trace() and TelemetryBackend.create_span(). This replaces #548, rebased onto 8.0.2 (which implemented OpenTelemetryBackend.create_span()).

  • Datadog: uses it as the span operation name and keeps name as the resource.
  • OpenTelemetry: records it as an operation_name span attribute, since OTel has no separate operation name.
  • New Relic: accepts it and ignores it, because FunctionTrace has no equivalent.

Behavior is unchanged when operation_name is not passed. Also corrects the monitoring README feature matrix, which still listed OpenTelemetry as not supporting span creation since 8.0.2, and adds an operation-name row.

JIRA:

N/A

Dependencies:

Supersedes #548. No other dependencies.

Merge deadline:

None

Installation instructions:

None

Testing instructions:

  1. Install test requirements: pip install -r requirements/test.txt
  2. Run pytest edx_django_utils/monitoring
  3. Expect all tests to pass, including the new test_create_span_with_operation_name, which checks:
    • Datadog: trace('some.operation', resource='some_function_name')
    • OpenTelemetry: start_as_current_span('some_function_name', attributes={'operation_name': 'some.operation'})
    • New Relic: FunctionTrace('some_function_name')
  4. If any backend receives different arguments, check failed.

Reviewers:

  • tag reviewer

Merge checklist:

  • All reviewers approved
  • CI build is green
  • Version bumped (8.1.0)
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed

Post merge:

  • Create a tag
  • Check new version is pushed to PyPi after tag-triggered build is
    finished.
  • Delete working branch (if not needed anymore)

Author concerns:

  • Custom TelemetryBackend subclasses must update their create_span signature to accept operation_name=None, otherwise function_trace() will raise a TypeError. This is noted in the changelog and is why the bump is a minor version (8.1.0).
  • The OpenTelemetry attribute key (operation_name) is my choice. Happy to rename it (e.g. operation.name) if reviewers prefer a different convention.

@rahulkanneri-2u
rahulkanneri-2u force-pushed the rahul/add-operation-name-to-create-span branch from d0b0091 to 375896d Compare October 1, 2026 11:38
Adds an optional operation_name argument to function_trace() and
TelemetryBackend.create_span(). Datadog uses it as the span operation
name (keeping name as the resource), OpenTelemetry records it as an
operation_name span attribute, and New Relic ignores it.

Also corrects the README feature matrix, which still listed OpenTelemetry
as not supporting span creation since 8.0.2.
@rahulkanneri-2u
rahulkanneri-2u force-pushed the rahul/add-operation-name-to-create-span branch from 375896d to 4ee4944 Compare October 1, 2026 11:39

@robrap robrap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor possible doc improvement.

- ❌
- ✅
- ✅
* - Operation name for a span (``function_trace(..., operation_name=...)``)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this accurate? Does this help clarify that this is just a different version of create span?

Suggested change
* - Operation name for a span (``function_trace(..., operation_name=...)``)
* - Create span with operation name (``function_trace(..., operation_name=...)``)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we want to follow-up with a small PR for this, we can. Didn't want you to be blocked on this minor note.

@robrap
robrap merged commit 9b2354a into openedx:master Oct 1, 2026
7 checks passed
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