Skip to content

Commit 5f101a3

Browse files
committed
update documentation
1 parent b650e58 commit 5f101a3

File tree

1 file changed

+87
-14
lines changed

1 file changed

+87
-14
lines changed

docs/core/tracing.md

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ under a subsegment, or you are doing multithreaded programming. Refer examples b
244244
}
245245
```
246246

247-
## Instrumenting SDK clients and HTTP calls
247+
## Instrumenting SDK clients
248248

249249
You should make sure to instrument the SDK clients explicitly based on the function dependency. You can instrument all of your AWS SDK for .NET clients by calling RegisterForAllServices before you create them.
250250

@@ -277,25 +277,98 @@ To instrument clients for some services and not others, call Register instead of
277277
Tracing.Register<IAmazonDynamoDB>()
278278
```
279279

280-
This functionality is a thin wrapper for AWS X-Ray .NET SDK. Refer details on [how to instrument SDK client with Xray](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-sdkclients.html) and [outgoing http calls](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-httpclients.html).
280+
This functionality is a thin wrapper for AWS X-Ray .NET SDK. Refer details on [how to instrument SDK client with Xray](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-sdkclients.html)
281+
282+
## Instrumenting outgoing HTTP calls
283+
284+
=== "Function.cs"
285+
286+
```c# hl_lines="7"
287+
using Amazon.XRay.Recorder.Handlers.System.Net;
288+
289+
public class Function
290+
{
291+
public Function()
292+
{
293+
var httpClient = new HttpClient(new HttpClientXRayTracingHandler(new HttpClientHandler()));
294+
var myIp = await httpClient.GetStringAsync("https://checkip.amazonaws.com/");
295+
}
296+
}
297+
```
298+
299+
More information about instrumenting [outgoing http calls](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-httpclients.html).
281300

282301
## AOT Support
283302

284303
Native AOT trims your application code as part of the compilation to ensure that the binary is as small as possible. .NET 8 for Lambda provides improved trimming support compared to previous versions of .NET.
285304

286-
These improvements offer the potential to eliminate build-time trimming warnings, but .NET will never be completely trim safe. This means that parts of libraries that your function relies on may be trimmed out as part of the compilation step. You can manage this by defining TrimmerRootAssemblies as part of your `.csproj` file as shown in the following example.
287305

288-
For the Tracing utility to work correctly and without trim warnings please add the following to your `.csproj` file
306+
### WithTracing()
289307

290-
```xml
291-
<ItemGroup>
292-
<TrimmerRootAssembly Include="AWSSDK.Core" />
293-
<TrimmerRootAssembly Include="AWSXRayRecorder.Core" />
294-
<TrimmerRootAssembly Include="AWSXRayRecorder.Handlers.AwsSdk" />
295-
<TrimmerRootAssembly Include="Amazon.Lambda.APIGatewayEvents" />
296-
</ItemGroup>
297-
```
308+
To use Tracing utility with AOT support you first need to add `WithTracing()` to the source generator you are using either the default `SourceGeneratorLambdaJsonSerializer`
309+
or the Powertools Logging utility [source generator](logging.md#aot-support){:target="_blank"} `PowertoolsSourceGeneratorSerializer`.
310+
311+
Examples:
312+
313+
=== "Without Powertools Logging"
314+
315+
```c# hl_lines="8"
316+
using AWS.Lambda.Powertools.Tracing;
317+
using AWS.Lambda.Powertools.Tracing.Serializers;
318+
319+
private static async Task Main()
320+
{
321+
Func<string, ILambdaContext, string> handler = FunctionHandler;
322+
await LambdaBootstrapBuilder.Create(handler, new SourceGeneratorLambdaJsonSerializer<LambdaFunctionJsonSerializerContext>()
323+
.WithTracing())
324+
.Build()
325+
.RunAsync();
326+
}
327+
```
328+
329+
=== "With Powertools Logging"
330+
331+
```c# hl_lines="10 11"
332+
using AWS.Lambda.Powertools.Logging;
333+
using AWS.Lambda.Powertools.Logging.Serializers;
334+
using AWS.Lambda.Powertools.Tracing;
335+
using AWS.Lambda.Powertools.Tracing.Serializers;
336+
337+
private static async Task Main()
338+
{
339+
Func<string, ILambdaContext, string> handler = FunctionHandler;
340+
await LambdaBootstrapBuilder.Create(handler,
341+
new PowertoolsSourceGeneratorSerializer<LambdaFunctionJsonSerializerContext>()
342+
.WithTracing())
343+
.Build()
344+
.RunAsync();
345+
}
346+
```
347+
348+
### Publishing
349+
350+
!!! warning "Publishing"
351+
Make sure you are publishing your code with `--self-contained true` and that you have `<TrimMode>partial</TrimMode>` in your `.csproj` file
352+
353+
### Trimming
354+
355+
!!! warning "Trim warnings"
356+
```xml
357+
<ItemGroup>
358+
<TrimmerRootAssembly Include="AWSSDK.Core" />
359+
<TrimmerRootAssembly Include="AWSXRayRecorder.Core" />
360+
<TrimmerRootAssembly Include="AWSXRayRecorder.Handlers.AwsSdk" />
361+
<TrimmerRootAssembly Include="Amazon.Lambda.APIGatewayEvents" />
362+
<TrimmerRootAssembly Include="bootstrap" />
363+
<TrimmerRootAssembly Include="Shared" />
364+
</ItemGroup>
365+
```
366+
367+
Note that when you receive a trim warning, adding the class that generates the warning to TrimmerRootAssembly might not resolve the issue. A trim warning indicates that the class is trying to access some other class that can't be determined until runtime. To avoid runtime errors, add this second class to TrimmerRootAssembly.
368+
369+
To learn more about managing trim warnings, see [Introduction to trim warnings](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/fixing-warnings) in the Microsoft .NET documentation.
298370

299-
Note that when you receive a trim warning, adding the class that generates the warning to TrimmerRootAssembly might not resolve the issue. A trim warning indicates that the class is trying to access some other class that can't be determined until runtime. To avoid runtime errors, add this second class to TrimmerRootAssembly.
371+
### Not supported
300372

301-
To learn more about managing trim warnings, see [Introduction to trim warnings](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/fixing-warnings) in the Microsoft .NET documentation.
373+
!!! warning "Not supported"
374+
Currently instrumenting SDK clients with `Tracing.RegisterForAllServices()` is not supported on AOT mode.

0 commit comments

Comments
 (0)