Skip to content

Commit

Permalink
feat: Allow ActivitySource to be specified in ServiceSettingsBase
Browse files Browse the repository at this point in the history
While we *could* remove ActivitySource from ClientHelper.Options, that would require the settings to be cloned if the user hasn't specified an activity source. That could potentially be done in ClientBuilderBase, but keeping the default separate from the user-specified activity source feels simpler.
  • Loading branch information
jskeet committed Apr 11, 2024
1 parent d6fa8a1 commit 0501add
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Google.Api.Gax.Grpc/ClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ClientHelper(Options options)
{
_versionCallSettings = _versionCallSettings.WithHeader(ApiVersionHeaderName, options.ApiVersion);
}
_activitySource = options.ActivitySource;
_activitySource = settings.ActivitySource ?? options.ActivitySource;
}

/// <summary>
Expand Down Expand Up @@ -214,7 +214,8 @@ public sealed class Options
public string ApiVersion { get; set; }

/// <summary>
/// The activity source to use for tracing, if any. This may be null.
/// The activity source to use for tracing, if any. This may be null. This is ignored
/// if <see cref="Settings"/> specifies an activity source.
/// Note: currently internal until we're ready to roll out OpenTelemetry support "properly".
/// </summary>
internal ActivitySource ActivitySource { get; set; }
Expand Down
9 changes: 9 additions & 0 deletions Google.Api.Gax.Grpc/ServiceSettingsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using Grpc.Core;
using Grpc.Core.Interceptors;
using System.Diagnostics;

namespace Google.Api.Gax.Grpc
{
Expand Down Expand Up @@ -42,6 +43,7 @@ protected ServiceSettingsBase(ServiceSettingsBase existing)
Scheduler = existing.Scheduler;
VersionHeaderBuilder = existing.VersionHeaderBuilder.Clone();
Interceptor = existing.Interceptor;
ActivitySource = existing.ActivitySource;
}

/// <summary>
Expand Down Expand Up @@ -84,5 +86,12 @@ protected ServiceSettingsBase(ServiceSettingsBase existing)
/// on or after that date are aware of this property.
/// </summary>
public Interceptor Interceptor { get; set; }

/// <summary>
/// An optional <see cref="ActivitySource"/>, which can override the default activity source used for tracing
/// calls from this client.
/// Note: currently internal until we're ready to roll out OpenTelemetry support "properly".
/// </summary>
internal ActivitySource ActivitySource { get; set; }
}
}

0 comments on commit 0501add

Please sign in to comment.