Resources
You are viewing the English version of this page because it has not yet been fully translated. Interested in helping out? See Contributing.
O resursă reprezintă entitatea care produce telemetrie, descrisă prin intermediul atributelor de resursă. De exemplu, un proces care produce telemetrie și rulează într-un container în Kubernetes are un nume de proces, un nume de pod, un namespace și, eventual, un nume de Kubernetes deployment. Toate cele patru atribute pot fi incluse în resursă.
În backend-ul tău de observabilitate, poți utiliza informațiile despre resursă pentru a investiga mai bine comportamentele relevante. De exemplu, dacă datele de tracing sau metricile indică o latență ridicată în sistem, poți restrânge investigația la un anumit container, pod sau Kubernetes deployment.
Resources should be assigned to a tracer, meter, and logger provider at its initialization, and are created much like attributes:
res := resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("myService"),
semconv.ServiceVersionKey.String("1.0.0"),
semconv.ServiceInstanceIDKey.String("abcdef12345"),
)
provider := sdktrace.NewTracerProvider(
...
sdktrace.WithResource(res),
)
Note the use of the semconv package to provide
conventional names for resource
attributes. This helps ensure that consumers of telemetry produced with these
semantic conventions can easily discover relevant attributes and understand
their meaning.
Resources can also be detected automatically through resource.Detector
implementations. These Detectors may discover information about the currently
running process, the operating system it is running on, the cloud provider
hosting that operating system instance, or any number of other resource
attributes.
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 host information.
resource.WithAttributes(attribute.String("foo", "bar")), // Add custom resource attributes.
// resource.WithDetectors(thirdparty.Detector{}), // Bring your own external Detector implementation.
)
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.
}
Comentariu
A fost utilă această pagină?
Thank you. Your feedback is appreciated!
Please let us know how we can improve this page. Your feedback is appreciated!