| 1 |
# OpenTelemetry AWS Lambda Resource Detector for Golang |
| 2 |
|
| 3 |
[![Go Reference][goref-image]][goref-url] |
| 4 |
[![Apache License][license-image]][license-url] |
| 5 |
|
| 6 |
This module detects resource attributes available in AWS Lambda. |
| 7 |
|
| 8 |
## Installation |
| 9 |
|
| 10 |
```bash |
| 11 |
go get -u go.opentelemetry.io/contrib/detectors/aws/lambda |
| 12 |
``` |
| 13 |
|
| 14 |
## Usage |
| 15 |
|
| 16 |
Create a sample Lambda Go application such as below. |
| 17 |
|
| 18 |
```go |
| 19 |
package main |
| 20 |
|
| 21 |
import ( |
| 22 |
"github.com/aws/aws-lambda-go/lambda" |
| 23 |
sdktrace "go.opencensus.io/otel/sdk/trace" |
| 24 |
lambdadetector "go.opentelemetry.io/contrib/detectors/aws/lambda" |
| 25 |
) |
| 26 |
|
| 27 |
func main() { |
| 28 |
detector := lambdadetector.NewResourceDetector() |
| 29 |
res, err := detector.Detect(context.Background()) |
| 30 |
if err != nil { |
| 31 |
fmt.Printf("failed to detect lambda resources: %v\n", err) |
| 32 |
} |
| 33 |
|
| 34 |
tp := sdktrace.NewTracerProvider( |
| 35 |
sdktrace.WithResource(res), |
| 36 |
) |
| 37 |
lambda.Start(<some lambda handler>) |
| 38 |
} |
| 39 |
``` |
| 40 |
|
| 41 |
Now your `TracerProvider` will have the following resource attributes and attach them to new spans: |
| 42 |
|
| 43 |
| Resource Attribute | Example Value | |
| 44 |
| --- | --- | |
| 45 |
| `cloud.provider` | aws |
| 46 |
|`cloud.region` | us-east-1 |
| 47 |
|`faas.name` | MyLambdaFunction |
| 48 |
|`faas.version` | $LATEST |
| 49 |
|`faas.instance` | 2021/06/28/[$LATEST]2f399eb14537447da05ab2a2e39309de |
| 50 |
|`faas.max_memory`| 128 |
| 51 |
|
| 52 |
Of note, `faas.id` and `cloud.account.id` are not set by the Lambda resource detector because they are not available outside a Lambda invocation. For this reason, when using the AWS Lambda Instrumentation these attributes are set as additional span attributes. |
| 53 |
|
| 54 |
## Useful links |
| 55 |
|
| 56 |
- For more on FaaS attribute conventions, visit <https://opentelemetry.io/docs/specs/semconv/faas/faas-spans/> |
| 57 |
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/> |
| 58 |
- For more about OpenTelemetry Go: <https://github.com/open-telemetry/opentelemetry-go> |
| 59 |
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url] |
| 60 |
|
| 61 |
## License |
| 62 |
|
| 63 |
Apache 2.0 - See [LICENSE][license-url] for more information. |
| 64 |
|
| 65 |
[license-url]: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/LICENSE |
| 66 |
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat |
| 67 |
[goref-image]: https://pkg.go.dev/badge/go.opentelemetry.io/contrib/detectors/aws/lambda.svg |
| 68 |
[goref-url]: https://pkg.go.dev/go.opentelemetry.io/contrib/detectors/aws/lambda |
| 69 |
[discussions-url]: https://github.com/open-telemetry/opentelemetry-go/discussions |