-
Notifications
You must be signed in to change notification settings - Fork 3
/
resource.go
45 lines (40 loc) · 1.3 KB
/
resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package otelKit
import (
"context"
"github.com/richelieu-yang/chimera/v3/src/core/errorKit"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.25.0"
)
func newDetailedResource(serviceName string, attributeMap map[string]string) (*resource.Resource, error) {
attributes := []attribute.KeyValue{
semconv.ServiceNameKey.String(serviceName),
}
for key, value := range attributeMap {
attributes = append(attributes, attribute.String(key, value))
}
res, err := resource.New(context.TODO(),
resource.WithOSType(),
resource.WithContainer(),
resource.WithFromEnv(),
resource.WithHost(),
resource.WithHostID(),
resource.WithProcess(),
resource.WithTelemetrySDK(),
resource.WithAttributes(attributes...),
)
if err != nil {
return nil, errorKit.Newf("fail to create resource")
}
return res, nil
}
// newResourceWithAttributes Record information about this application in a Resource.
func newResourceWithAttributes(serviceName string, attributeMap map[string]string) *resource.Resource {
var attrs = []attribute.KeyValue{
semconv.ServiceNameKey.String(serviceName),
}
for key, value := range attributeMap {
attrs = append(attrs, attribute.String(key, value))
}
return resource.NewWithAttributes(semconv.SchemaURL, attrs...)
}