Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
the new database semantic conventions are enabled.
([#4245](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4245))

* Add instrumentation scope version and schema URL to traces.
([#4095](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4095))

## 1.15.1-beta.1

Released 2026-Apr-21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ static bool GetCommandAndKey(
name = StackExchangeRedisConnectionInstrumentation.ActivityName;
}

var activity = StackExchangeRedisConnectionInstrumentation.ActivitySource.StartActivity(
var activitySource =
Comment thread
martincostello marked this conversation as resolved.
options.EmitNewAttributes && options.EmitOldAttributes ?
StackExchangeRedisConnectionInstrumentation.ActivitySourceBoth :
options.EmitNewAttributes ?
StackExchangeRedisConnectionInstrumentation.ActivitySourceNew :
StackExchangeRedisConnectionInstrumentation.ActivitySource;

var activity = activitySource.StartActivity(
name,
ActivityKind.Client,
parentActivity?.Context ?? default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\Shared\ActivitySourceFactory.cs" Link="Includes\ActivitySourceFactory.cs" />
<Compile Include="$(RepoRoot)\src\Shared\AssemblyVersionExtensions.cs" Link="Includes\AssemblyVersionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\Shared\DatabaseSemanticConventionHelper.cs" Link="Includes\DatabaseSemanticConventionHelper.cs" />
<Compile Include="$(RepoRoot)\src\Shared\EnvironmentVariables\*.cs" Link="Includes\EnvironmentVariables\%(Filename).cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection;
using OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation;
using OpenTelemetry.Internal;
using OpenTelemetry.Trace;
Expand All @@ -18,12 +17,17 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis;
internal sealed class StackExchangeRedisConnectionInstrumentation : IDisposable
{
internal const string RedisDatabaseIndexKeyName = "db.redis.database_index";
internal static readonly Assembly Assembly = typeof(StackExchangeRedisConnectionInstrumentation).Assembly;
#pragma warning disable IDE0370 // Suppression is unnecessary
internal static readonly string ActivitySourceName = Assembly.GetName().Name!;
#pragma warning restore IDE0370 // Suppression is unnecessary
internal static readonly string ActivityName = ActivitySourceName + ".Execute";
internal static readonly ActivitySource ActivitySource = new(ActivitySourceName, Assembly.GetPackageVersion());

internal static readonly Version SemanticConventionsVersion = new(1, 23, 0);
internal static readonly ActivitySource ActivitySource = ActivitySourceFactory.Create<StackExchangeRedisConnectionInstrumentation>(SemanticConventionsVersion);

internal static readonly Version SemanticConventionsVersionNew = new(1, 28, 0);
internal static readonly ActivitySource ActivitySourceNew = ActivitySourceFactory.Create<StackExchangeRedisConnectionInstrumentation>(SemanticConventionsVersionNew);

internal static readonly ActivitySource ActivitySourceBoth = ActivitySourceFactory.Create<StackExchangeRedisConnectionInstrumentation>(null);

internal static readonly string ActivityName = $"{ActivitySource.Name}.Execute";
Comment thread
martincostello marked this conversation as resolved.

internal static readonly IEnumerable<KeyValuePair<string, object?>> OldCreationTags =
[
new(SemanticConventions.AttributeDbSystem, "redis")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static TracerProviderBuilder AddRedisInstrumentation(
}

return builder
.AddSource(StackExchangeRedisConnectionInstrumentation.ActivitySourceName)
.AddSource(StackExchangeRedisConnectionInstrumentation.ActivitySource.Name)
.AddInstrumentation(sp =>
{
var instrumentation = sp.GetRequiredService<StackExchangeRedisInstrumentation>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ public void SuccessfulCommandTest(

// TODO VerifySamplingParameters(sampler.LatestSamplingParameters);
}

string? expectedSchemaUrl = (emitOldAttributes, emitNewAttributes) switch
{
(false, true) => "https://opentelemetry.io/schemas/1.28.0",
(true, false) => "https://opentelemetry.io/schemas/1.23.0",
_ => null,
};

foreach (var activity in exportedItems)
{
Assert.Equal("OpenTelemetry.Instrumentation.StackExchangeRedis", activity.Source.Name);
Assert.NotNull(activity.Source.Version);
Assert.NotEmpty(activity.Source.Version);
Assert.Equal(expectedSchemaUrl, activity.Source.TelemetrySchemaUrl);
}
}

[EnabledOnDockerPlatformFact(DockerPlatform.Linux)]
Expand Down Expand Up @@ -551,6 +566,10 @@ private static void VerifyNewActivityData(Activity activity, bool isSet, EndPoin
Assert.Equal(dbOperationName, activity.GetTagValue(SemanticConventions.AttributeDbOperationName));
Assert.Equal(dbQueryText, activity.GetTagValue(SemanticConventions.AttributeDbQueryText));

Assert.Equal("OpenTelemetry.Instrumentation.StackExchangeRedis", activity.Source.Name);
Assert.NotNull(activity.Source.Version);
Assert.NotEmpty(activity.Source.Version);

VerifyEndPoint(activity, endPoint);
}

Expand Down
Loading