Skip to content

Conversation

@RohitRanjanMS
Copy link
Member

@RohitRanjanMS RohitRanjanMS commented Oct 13, 2025

  • Updated worker instrumentation to improve telemetry handling.
  • Added support for OpenTelemetry schema version backward compatibility, allowing users to adopt newer schema versions at their own pace.
  • Removed the previous “internal” activity that was created solely for context propagation but could not be tracked.
  • Introduced a new internal activity that is now published and provides proper context propagation.

Issue describing the changes in this PR

resolves #3198
resolves #3199

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • I have added all required tests (Unit tests, E2E tests)

@RohitRanjanMS RohitRanjanMS requested a review from Copilot October 13, 2025 08:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates worker instrumentation to improve telemetry handling by adding support for OpenTelemetry schema version backward compatibility and introducing a new internal activity system for proper context propagation.

  • Added support for multiple OpenTelemetry schema versions (1.17.0 and 1.37.0) with backward compatibility
  • Replaced the old activity system with a new telemetry provider architecture that creates properly tracked activities
  • Updated trace context to include attributes and modified various telemetry-related components

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/DotNetWorker.Core/FunctionsApplication.cs Replaced old activity factory with new telemetry provider system
src/DotNetWorker.Core/Diagnostics/ Added new telemetry provider architecture with schema version support
src/DotNetWorker.Core/Context/ Enhanced trace context to include attributes
src/DotNetWorker.OpenTelemetry/ Updated OpenTelemetry package versions and configuration
test/ Updated tests to work with new telemetry system and validate schema versions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@RohitRanjanMS RohitRanjanMS requested a review from jviau October 13, 2025 09:32
Copy link
Contributor

@jviau jviau left a comment

Choose a reason for hiding this comment

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

This PR has a lot of changes that impact the telemetry from DotNetWorker.Core irrespective of customer using OTel or not. These seem like breaking changes for those customers.


using var logScope = _logger.BeginScope(scope);
using Activity? invokeActivity = _functionActivitySourceFactory.StartInvoke(context);
using var logScope = _logger.BeginScope(_functionTelemetryProvider.GetTelemetryAttributes(context).ToList());
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a significant change to log scope. Also what happens if OTel is not enabled here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I’ve kept all existing attributes intact and added new ones according to v17.0 without any breaking changes.
If OpenTelemetry/AppInsights isn’t enabled, the activity will be null, but you’ll always have the scope.
The default specification version is v37.0

Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this new scope approach be adding OTel specific attributes even when customer is using legacy app insights SDK?

I also wonder if we need all of those in the log scope specifically? Or can they be part of the OTel resource?

internal const string RegionNameEnvVar = "REGION_NAME";
internal const string ResourceGroupEnvVar = "WEBSITE_RESOURCE_GROUP";
internal const string OwnerNameEnvVar = "WEBSITE_OWNER_NAME";
internal const string WorkerSchemaVersion = "1.37.0";
Copy link
Contributor

Choose a reason for hiding this comment

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

This directly ties to OTel schema version to the package. This will prevent us from servicing old schema versions in new releases. Is that acceptable?

Copy link
Member Author

Choose a reason for hiding this comment

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

I’ll add support for new versions as they’re released. Version 1.37 will remain our baseline, and we’ll bump it to a newer base in the next major release.

@RohitRanjanMS RohitRanjanMS requested a review from jviau October 17, 2025 21:48
/// Gets the attributes associated with the trace.
/// </summary>
public abstract IReadOnlyDictionary<string, string> Attributes { get; }
public virtual IReadOnlyDictionary<string, string> Attributes => new Dictionary<string, string>();
Copy link
Contributor

Choose a reason for hiding this comment

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

consider using a common empty dictionary to avoid any allocations when this is not overridden.

Could even use ImmutableDictionary<string, string>.Empty

{
OpenTelemetrySchemaVersion.V1_17_0 => new TelemetryProviderV1_17_0(),
OpenTelemetrySchemaVersion.V1_37_0 => new TelemetryProviderV1_37_0(),
_ => throw new InvalidOperationException($"Unsupported OpenTelemetry schema version: {version}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider ArgumentOutOfRangeException or ArgumentException

Activator.CreateInstance(startupCodeExecutorInfoAttr.StartupCodeExecutorType) as WorkerExtensionStartup;
startupCodeExecutorInstance!.Configure(builder);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit remove extra whitespace

Suggested change
}
}

=> OpenTelemetrySchemaVersion.V1_37_0;

protected override ActivityKind Kind
=> ActivityKind.Internal;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we assuming the func host emits the Server span?


using var logScope = _logger.BeginScope(scope);
using Activity? invokeActivity = _functionActivitySourceFactory.StartInvoke(context);
using var logScope = _logger.BeginScope(_functionTelemetryProvider.GetTelemetryAttributes(context).ToList());
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this new scope approach be adding OTel specific attributes even when customer is using legacy app insights SDK?

I also wonder if we need all of those in the log scope specifically? Or can they be part of the OTel resource?

internal const string CloudPlatform = "cloud.platform";
internal const string CloudRegion = "cloud.region";
internal const string CloudResourceId = "cloud.resource.id";
internal const string CloudResourceId = "cloud.resource_id";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not a schema breaking change?

Copy link
Member

Choose a reason for hiding this comment

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

Good question. Wasn't always the cloud resource id defined as cloud.resource_id? Tried to see if there was a resource change from cloud.resource.id to cloud.resource_id but didn't find that in the schema specs.

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.

Versioning for Span and Metrics specifications It should be possible to completely disable tracing on the host

4 participants