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

Update Go resource example #3970

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Changes from all commits
Commits
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
15 changes: 9 additions & 6 deletions content/en/docs/languages/go/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ hosting that operating system instance, or any number of other resource
attributes.

```go
res, err := resource.New(context.Background(),
resource.WithFromEnv(), // Pull attributes from OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME environment variables.
resource.WithTelemetrySDK(), // Provide information about the OpenTelemetry SDK used.
res, err := resource.New(
context.Background(),
resource.WithFromEnv(), // Discover and provide attributes from OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME environment variables.
resource.WithTelemetrySDK(), // Discover and provide information about the OpenTelemetry SDK used.
resource.WithProcess(), // Discover and provide process information.
resource.WithOS(), // Discover and provide OS information.
resource.WithContainer(), // Discover and provide container information.
resource.WithHost(), // Discover and provide information.
resource.WithHost(), // Discover and provide host information.
resource.WithAttributes(attribute.String("foo", "bar")), // Add custom resource attributes.
// resource.WithDetectors(thirdparty.Detector{}), // Bring your own external Detector implementation.
)
if err != nil {
log.Println(err) // Log issues during resource creation. Note that resource.New still returns a resource.
if errors.Is(err, resource.ErrPartialResource) || errors.Is(err, resource.ErrSchemaURLConflict) {
log.Println(err) // Log non-fatal issues.
} else if err != nil {
log.Fatalln(err) // The error may be fatal.
}
```
Loading