diff --git a/Google.Api.Generator/Generation/ServiceAbstractClientClassCodeGenerator.cs b/Google.Api.Generator/Generation/ServiceAbstractClientClassCodeGenerator.cs index c03abd9c..44c8b583 100644 --- a/Google.Api.Generator/Generation/ServiceAbstractClientClassCodeGenerator.cs +++ b/Google.Api.Generator/Generation/ServiceAbstractClientClassCodeGenerator.cs @@ -24,6 +24,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -57,14 +58,17 @@ private ClassDeclarationSyntax Generate() var defaultScopes = DefaultScopes(); var serviceMetadata = ServiceMetadata(defaultEndpoint, defaultScopes); var channelPool = ChannelPool(serviceMetadata); + var activitySource = DefaultActivitySource(); + var activitySourceName = DefaultActivitySourceName(activitySource); var createAsync = CreateAsync(); var create = Create(); var createFromCallInvoker = CreateFromCallInvoker(); var shutdown = ShutdownDefaultChannelsAsync(channelPool, create, createAsync); var grpcClient = GrpcClient(); cls = cls.AddMembers( - defaultEndpoint, defaultScopes, serviceMetadata, channelPool, - createAsync, create, createFromCallInvoker, shutdown, grpcClient); + defaultEndpoint, defaultScopes, serviceMetadata, channelPool, + activitySource, activitySourceName, createAsync, create, + createFromCallInvoker, shutdown, grpcClient); cls = cls.AddMembers(Mixins().ToArray()); var methods = ServiceMethodGenerator.Generate(_ctx, _svc, inAbstract: true); cls = cls.AddMembers(methods.ToArray()); @@ -86,6 +90,16 @@ private PropertyDeclarationSyntax DefaultScopes() => XmlDoc.Summary($"The default {_svc.DocumentationName} scopes."), XmlDoc.Remarks($"The default {_svc.DocumentationName} scopes are:", XmlDoc.UL(_svc.DefaultScopes))); + private PropertyDeclarationSyntax DefaultActivitySource() => + AutoProperty(Internal | Static, _ctx.Type(), "ClientActivitySource") + .WithInitializer(_ctx.Type(typeof(ActivitySourceHelper)).Call(nameof(ActivitySourceHelper.FromClientType), _ctx.Type(_svc.ClientAbstractTyp))()); + + private PropertyDeclarationSyntax DefaultActivitySourceName(PropertyDeclarationSyntax activitySource) => + AutoProperty(Public | Static, _ctx.Type(), "ActivitySourceName") + .WithInitializer(activitySource.Access(nameof(ActivitySource.Name))) + .WithXmlDoc(XmlDoc.Summary( + "The name of ActivitySource associated with the ", _ctx.CurrentType, ".")); + private PropertyDeclarationSyntax ServiceMetadata(PropertyDeclarationSyntax defaultEndpoint, PropertyDeclarationSyntax defaultScopes) { var serviceDescriptor = _ctx.Type(_svc.ProtoTyp).Access("Descriptor"); diff --git a/Google.Api.Generator/Generation/ServiceImplClientClassGenerator.cs b/Google.Api.Generator/Generation/ServiceImplClientClassGenerator.cs index b1dc75c2..e4fb1e05 100644 --- a/Google.Api.Generator/Generation/ServiceImplClientClassGenerator.cs +++ b/Google.Api.Generator/Generation/ServiceImplClientClassGenerator.cs @@ -14,22 +14,21 @@ using Google.Api.Gax.Grpc; using Google.Api.Generator.ProtoUtils; -using Google.Api.Generator.Utils.Roslyn; using Google.Api.Generator.Utils; +using Google.Api.Generator.Utils.Roslyn; using Google.LongRunning; using Google.Protobuf; +using Google.Protobuf.Reflection; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; -using System.Net; using static Google.Api.Generator.Utils.Roslyn.Modifier; using static Google.Api.Generator.Utils.Roslyn.RoslynBuilder; -using Microsoft.CodeAnalysis.CSharp; -using Google.Protobuf.Reflection; -using Microsoft.Extensions.Logging; -using Google.Api.Gax; namespace Google.Api.Generator.Generation { @@ -104,12 +103,14 @@ private MemberDeclarationSyntax CtorGrpcClient(PropertyDeclarationSyntax grpcCli var settings = Parameter(_ctx.Type(_svc.SettingsTyp), "settings"); var logger = Parameter(_ctx.Type(), "logger"); var effectiveSettings = Local(_ctx.Type(_svc.SettingsTyp), "effectiveSettings"); + var activitySource = Local(_ctx.Type(), "activitySource"); var clientHelper = Local(_ctx.Type(), "clientHelper"); return Ctor(Public, _ctx.CurrentTyp)(grpcClient, settings, logger) .WithBody( grpcClientProperty.Assign(grpcClient), effectiveSettings.WithInitializer(settings.NullCoalesce(_ctx.Type(_svc.SettingsTyp).Call("GetDefault")())), - clientHelper.WithInitializer(New(_ctx.Type())(effectiveSettings, logger)), + activitySource.WithInitializer(_ctx.Type(_svc.ClientAbstractTyp).Access("ClientActivitySource")), + clientHelper.WithInitializer(New(_ctx.Type())(effectiveSettings, logger, activitySource)), _svc.Methods.OfType().Select(m => StandardLroClient(m, logger)), _svc.Methods.OfType().Select(m => NonStandardLroClient(m, logger)), _svc.Mixins.Select(m => MixinClient(m, logger)),