Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenTelemetry.Instrumentation.AWSLambda]: update README according to the recent code changes. #1234

Merged
merged 23 commits into from
Jun 15, 2023
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ffc089b
[OpenTelemetry.Instrumentation.AWSLambda]: bringing README.md up to date
rypdal Jun 13, 2023
85fbfe9
Merge branch 'main' into feature/actualize-aws-lambda-readme
rypdal Jun 14, 2023
93c6d88
[OpenTelemetry.Instrumentation.AWSLambda]: README update: fixed missp…
rypdal Jun 14, 2023
5e50a39
[OpenTelemetry.Instrumentation.AWSLambda]: README update: lines refor…
rypdal Jun 14, 2023
d119455
[OpenTelemetry.Instrumentation.AWSLambda]: README update: lines refor…
rypdal Jun 14, 2023
ba64135
Update src/OpenTelemetry.Instrumentation.AWSLambda/README.md
rypdal Jun 14, 2023
db21d55
Update src/OpenTelemetry.Instrumentation.AWSLambda/README.md
rypdal Jun 14, 2023
ba873e4
Update src/OpenTelemetry.Instrumentation.AWSLambda/README.md
rypdal Jun 14, 2023
2053e03
[OpenTelemetry.Instrumentation.AWSLambda]: README update: review sugg…
rypdal Jun 14, 2023
6ebe475
[OpenTelemetry.Instrumentation.AWSLambda]: README update: fixed the r…
rypdal Jun 14, 2023
d0619eb
[OpenTelemetry.Instrumentation.AWSLambda]: README update: fixed the r…
rypdal Jun 14, 2023
322c892
[OpenTelemetry.Instrumentation.AWSLambda]: README update: removed lin…
rypdal Jun 14, 2023
cc1ecb8
[OpenTelemetry.Instrumentation.AWSLambda]: README update: consistent …
rypdal Jun 14, 2023
6528d9d
[OpenTelemetry.Instrumentation.AWSLambda]: README update: removed red…
rypdal Jun 14, 2023
f211089
Update src/OpenTelemetry.Instrumentation.AWSLambda/README.md
rypdal Jun 15, 2023
9d233bd
Update src/OpenTelemetry.Instrumentation.AWSLambda/README.md
rypdal Jun 15, 2023
f1239d9
Update src/OpenTelemetry.Instrumentation.AWSLambda/README.md
rypdal Jun 15, 2023
59e5d22
Update src/OpenTelemetry.Instrumentation.AWSLambda/README.md
rypdal Jun 15, 2023
a7457a3
Update src/OpenTelemetry.Instrumentation.AWSLambda/README.md
rypdal Jun 15, 2023
9a088e2
[OpenTelemetry.Instrumentation.AWSLambda]: README update: some re-for…
rypdal Jun 15, 2023
091edcf
[OpenTelemetry.Instrumentation.AWSLambda]: README update: some clarif…
rypdal Jun 15, 2023
182cf10
[OpenTelemetry.Instrumentation.AWSLambda]: README update: tailing space
rypdal Jun 15, 2023
ca1fc7d
Merge branch 'main' into feature/actualize-aws-lambda-readme
Kielek Jun 15, 2023
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
41 changes: 34 additions & 7 deletions src/OpenTelemetry.Instrumentation.AWSLambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,44 @@ Add `AddAWSLambdaConfigurations()` to `TracerProvider`.
```csharp
TracerProvider tracerProvider = Sdk.CreateTracerProviderBuilder()
// add other instrumentations
.AddAWSLambdaConfigurations()
.AddAWSLambdaConfigurations(options => options.DisableAwsXRayContextExtraction = true)
Kielek marked this conversation as resolved.
Show resolved Hide resolved
.Build();
```

### AWSLambdaInstrumentationOptions

`AWSLambdaInstrumentationOptions` contains various properties to configure
AWS lambda instrumentation:

* [`DisableAwsXRayContextExtraction`](/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaInstrumentationOptions.cs)
* [`SetParentFromBatch`](/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaInstrumentationOptions.cs)

## Instrumentation

`AWSLambdaWrapper` contains tracing methods covering different types of
function handler method signatures. `AWSLambdaWrapper.Trace()` and
`AWSLambdaWrapper.TraceAsync()` are used for wrapping synchronous
and asynchronous function handlers respectively. The `ActivityContext parentContext`
parameter is optional and used to pass a custom parent context. If the parent
is not passed explicitly then it's either extracted from the
input parameter or uses AWS X-Ray headers if AWS X-Ray context extraction is
enabled (see configuration property `DisableAwsXRayContextExtraction`).
The sequence of the parent extraction:
`explicit parent` -> `parent from input parameter` -> `AWS X-Ray headers` -> `default`
The parent extraction is supported for the input types listed in the table below:

| Type | Parent extraction source |
|------|--------------------------|
| `APIGatewayProxyRequest, APIGatewayHttpApiV2ProxyRequest` | HTTP headers of the request |
| `SQSEvent` | Attributes of the last `SQSMessage` (if `SetParentFromMessageBatch` is `true`) |
| `SNSEvent` | Attributes of the last `SNSRecord` |

### Lambda Function

1. Create a wrapper function with the same signature as the original Lambda function.
Call `AWSLambdaWrapper.Trace()` API and pass `TracerProvider`, original Lambda function
and its inputs as parameters.
1. Create a wrapper function with the same signature as the original Lambda
function but an added ILambdaContext parameter if it was not already present.
Call `AWSLambdaWrapper.Trace()` or `AWSLambdaWrapper.TraceAsync()` API and pass
`TracerProvider`, original Lambda function and its parameters.

2. Set the wrapper function as the Lambda handler input.

Expand All @@ -48,14 +75,14 @@ public string OriginalFunctionHandler(JObject input, ILambdaContext context)

For using base classes from package [Amazon.Lambda.AspNetCoreServer](https://github.com/aws/aws-lambda-dotnet/tree/master/Libraries/src/Amazon.Lambda.AspNetCoreServer#amazonlambdaaspnetcoreserver),
override the `FunctionHandlerAsync` function in `LambdaEntryPoint.cs` file. Call
`AWSLambdaWrapper.Trace()` API and pass `TracerProvider`, original Lambda function
`AWSLambdaWrapper.TraceAsync()` API and pass `TracerProvider`, original Lambda function
and its inputs as parameters. Below is an example if using `APIGatewayProxyFunction`
as base class.

```csharp
public override async Task<APIGatewayProxyResponse> FunctionHandlerAsync(
APIGatewayProxyRequest request, ILambdaContext lambdaContext)
=> await AWSLambdaWrapper.Trace(tracerProvider, base.FunctionHandlerAsync,
=> await AWSLambdaWrapper.TraceAsync(tracerProvider, base.FunctionHandlerAsync,
request, lambdaContext);
```

Expand All @@ -75,7 +102,7 @@ public class Function
.AddHttpClientInstrumentation()
.AddAWSInstrumentation()
.AddOtlpExporter()
.AddAWSLambdaConfigurations()
.AddAWSLambdaConfigurations(options => options.DisableAwsXRayContextExtraction = true)
.Build();
}

Expand Down