Skip to content

Commit 5476020

Browse files
Add support for distributed tracing in generated clients (Azure#49691)
* feat: add support for distributed tracing in clients * refactor to use more visitor APIs * address initial feedback * address feedback * more feedback & bump versions * nits & regen
1 parent 7b4dd2f commit 5476020

File tree

62 files changed

+2107
-785
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2107
-785
lines changed

eng/Packages.Data.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@
206206
</ItemGroup>
207207

208208
<ItemGroup Condition="'$(IsGeneratorLibrary)' == 'true'">
209-
<PackageReference Update="Microsoft.TypeSpec.Generator.ClientModel" Version="1.0.0-alpha.20250429.2" />
210-
<PackageReference Update="Microsoft.TypeSpec.Generator.Input" Version="1.0.0-alpha.20250429.2" />
209+
<PackageReference Update="Microsoft.TypeSpec.Generator.ClientModel" Version="1.0.0-alpha.20250501.3" />
210+
<PackageReference Update="Microsoft.TypeSpec.Generator.Input" Version="1.0.0-alpha.20250501.3" />
211211
<PackageReference Update="Azure.Generator" Version="1.0.0-alpha.20250429.2" />
212212
<PackageReference Update="System.ClientModel" Version="1.3.0" />
213213
</ItemGroup>

eng/packages/http-client-csharp/generator/Azure.Generator/src/Azure.Generator.csproj

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<!-- Check if the folder does not exist -->
1616
<Error Condition="!Exists('..\..\..\node_modules\@typespec\http-client-csharp')" Text="Emitter has not been built please run `npm ci` from repo root folder, and followed by `npm run build` from ./eng/packages/http-client-csharp folder." />
1717
</Target>
18-
18+
1919
<!-- Copy output to package dist path for local execution -->
2020
<Target Name="CopyForNpmPackage" AfterTargets="Build">
2121
<Message Text="Copying output to dist path" Importance="high" />
@@ -40,6 +40,21 @@
4040
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\RequestHeaderExtensions.cs" LinkBase="Shared/Core">
4141
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4242
</Compile>
43+
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\AppContextSwitchHelper.cs" LinkBase="Shared/Core">
44+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
45+
</Compile>
46+
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\ClientDiagnostics.cs" LinkBase="Shared/Core">
47+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
48+
</Compile>
49+
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\DiagnosticScopeFactory.cs" LinkBase="Shared/Core">
50+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
51+
</Compile>
52+
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\DiagnosticScope.cs" LinkBase="Shared/Core">
53+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
54+
</Compile>
55+
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\HttpMessageSanitizer.cs" LinkBase="Shared/Core">
56+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
57+
</Compile>
4358
</ItemGroup>
4459

4560
</Project>

eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureClientGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using Azure.Generator.Visitors;
45
using Microsoft.CodeAnalysis;
56
using Microsoft.TypeSpec.Generator;
67
using Microsoft.TypeSpec.Generator.ClientModel;
@@ -49,5 +50,6 @@ protected override void Configure()
4950
var sharedSourceDirectory = Path.Combine(Path.GetDirectoryName(typeof(AzureClientGenerator).Assembly.Location)!, "Shared", "Core");
5051
AddSharedSourceDirectory(sharedSourceDirectory);
5152
AddVisitor(new NamespaceVisitor());
53+
AddVisitor(new DistributedTracingVisitor());
5254
}
5355
}

eng/packages/http-client-csharp/generator/Azure.Generator/src/Primitives/NewAzureProjectScaffolding.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System;
88
using System.Collections.Generic;
99
using System.Linq;
10+
using System.Numerics;
1011

1112
namespace Azure.Generator.Primitives
1213
{
@@ -52,31 +53,40 @@ protected override string GetSourceProjectFileContent()
5253

5354
if (hasOperation)
5455
{
55-
builder.CompileIncludes.Add(new CSharpProjectWriter.CSProjCompileInclude(GetCompileInclude("RawRequestUriBuilder.cs", pathSegmentCount), SharedSourceLinkBase));
56-
builder.CompileIncludes.Add(new CSharpProjectWriter.CSProjCompileInclude(GetCompileInclude("TypeFormatters.cs", pathSegmentCount), SharedSourceLinkBase));
57-
builder.CompileIncludes.Add(new CSharpProjectWriter.CSProjCompileInclude(GetCompileInclude("RequestHeaderExtensions.cs", pathSegmentCount), SharedSourceLinkBase));
56+
foreach (var file in _operationSharedFiles)
57+
{
58+
builder.CompileIncludes.Add(new CSharpProjectWriter.CSProjCompileInclude(GetCompileInclude(file, pathSegmentCount), SharedSourceLinkBase));
59+
}
5860
}
5961

6062
if (hasLongRunningOperation)
6163
{
6264
foreach (var file in _lroSharedFiles)
6365
{
64-
builder.CompileIncludes.Add(new CSharpProjectWriter.CSProjCompileInclude(GetCompileInclude(file, pathSegmentCount), "Shared/Core"));
66+
builder.CompileIncludes.Add(new CSharpProjectWriter.CSProjCompileInclude(GetCompileInclude(file, pathSegmentCount), SharedSourceLinkBase));
6567
}
6668
}
6769

6870
return builder.Write();
6971
}
7072

71-
private static readonly IReadOnlyList<string> _lroSharedFiles =
73+
private static readonly IReadOnlyList<string> _operationSharedFiles =
7274
[
75+
"RawRequestUriBuilder.cs",
76+
"TypeFormatters.cs",
77+
"RequestHeaderExtensions.cs",
7378
"AppContextSwitchHelper.cs",
74-
"AsyncLockWithValue.cs",
75-
"FixedDelayWithNoJitterStrategy.cs",
7679
"ClientDiagnostics.cs",
7780
"DiagnosticScopeFactory.cs",
7881
"DiagnosticScope.cs",
7982
"HttpMessageSanitizer.cs",
83+
"TrimmingAttribute.cs",
84+
];
85+
86+
private static readonly IReadOnlyList<string> _lroSharedFiles =
87+
[
88+
"AsyncLockWithValue.cs",
89+
"FixedDelayWithNoJitterStrategy.cs",
8090
"IOperationSource.cs",
8191
"NextLinkOperationImplementation.cs",
8292
"OperationFinalStateVia.cs",
@@ -86,7 +96,6 @@ protected override string GetSourceProjectFileContent()
8696
"OperationPoller.cs",
8797
"SequentialDelayStrategy.cs",
8898
"TaskExtensions.cs",
89-
"TrimmingAttribute.cs",
9099
"VoidValue.cs"
91100
];
92101

@@ -131,4 +140,4 @@ private string GetCompileInclude(string fileName, int pathSegmentCount)
131140
return $"{MSBuildThisFileDirectory}{string.Concat(Enumerable.Repeat(ParentDirectory, pathSegmentCount))}{RelativeCoreSegment}{fileName}";
132141
}
133142
}
134-
}
143+
}

0 commit comments

Comments
 (0)