@@ -10,7 +10,7 @@ Resources should be assigned to a tracer provider at its initialization, and are
10
10
created much like attributes:
11
11
12
12
``` go
13
- resources := resource.NewWithAttributes (
13
+ res := resource.NewWithAttributes (
14
14
semconv.SchemaURL ,
15
15
semconv.ServiceNameKey .String (" myService" ),
16
16
semconv.ServiceVersionKey .String (" 1.0.0" ),
@@ -19,7 +19,7 @@ resources := resource.NewWithAttributes(
19
19
20
20
provider := sdktrace.NewTracerProvider (
21
21
...
22
- sdktrace.WithResource (resources ),
22
+ sdktrace.WithResource (res ),
23
23
)
24
24
```
25
25
@@ -36,13 +36,17 @@ hosting that operating system instance, or any number of other resource
36
36
attributes.
37
37
38
38
``` go
39
- resources := resource.New (context.Background (),
40
- resource.WithFromEnv (), // pull attributes from OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME environment variables
41
- resource.WithProcess (), // This option configures a set of Detectors that discover process information
42
- resource.WithOS (), // This option configures a set of Detectors that discover OS information
43
- resource.WithContainer (), // This option configures a set of Detectors that discover container information
44
- resource.WithHost (), // This option configures a set of Detectors that discover host information
45
- resource.WithDetectors (thirdparty.Detector {}), // Bring your own external Detector implementation
46
- resource.WithAttributes (attribute.String (" foo" , " bar" )), // Or specify resource attributes directly
39
+ res , err := resource.New (context.Background (),
40
+ resource.WithFromEnv (), // Pull attributes from OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME environment variables.
41
+ resource.WithTelemetrySDK (), // Provide information about the OpenTelemetry SDK used.
42
+ resource.WithProcess (), // Discover and provide process information.
43
+ resource.WithOS (), // Discover and provide OS information.
44
+ resource.WithContainer (), // Discover and provide container information.
45
+ resource.WithHost (), // Discover and provide information.
46
+ resource.WithAttributes (attribute.String (" foo" , " bar" )), // Add custom resource attributes.
47
+ // resource.WithDetectors(thirdparty.Detector{}), // Bring your own external Detector implementation.
47
48
)
49
+ if err != nil {
50
+ log.Println (err) // Log issues during resource creation. Note that resource.New still returns a resource.
51
+ }
48
52
```
0 commit comments