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

Fix complication bug in Go Resources page #3949

Merged
merged 1 commit into from
Feb 6, 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
24 changes: 14 additions & 10 deletions content/en/docs/languages/go/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Resources should be assigned to a tracer provider at its initialization, and are
created much like attributes:

```go
resources := resource.NewWithAttributes(
res := resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("myService"),
semconv.ServiceVersionKey.String("1.0.0"),
Expand All @@ -19,7 +19,7 @@ resources := resource.NewWithAttributes(

provider := sdktrace.NewTracerProvider(
...
sdktrace.WithResource(resources),
sdktrace.WithResource(res),
)
```

Expand All @@ -36,13 +36,17 @@ hosting that operating system instance, or any number of other resource
attributes.

```go
resources := resource.New(context.Background(),
resource.WithFromEnv(), // pull attributes from OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME environment variables
resource.WithProcess(), // This option configures a set of Detectors that discover process information
resource.WithOS(), // This option configures a set of Detectors that discover OS information
resource.WithContainer(), // This option configures a set of Detectors that discover container information
resource.WithHost(), // This option configures a set of Detectors that discover host information
resource.WithDetectors(thirdparty.Detector{}), // Bring your own external Detector implementation
resource.WithAttributes(attribute.String("foo", "bar")), // Or specify resource attributes directly
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.
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.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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is guaranteed. We make this guarantee for two specific error types, but the user needs to check res is not nil before they can safely use it in all cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make a followup PR once open-telemetry/opentelemetry-go#4887 is merged.

}
```