-
Notifications
You must be signed in to change notification settings - Fork 67
/
common.go
37 lines (30 loc) 路 886 Bytes
/
common.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
package telemetry
import (
"fmt"
"os"
"github.com/kubeshop/tracetest/server/version"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
)
func getAgentServiceName(serviceName string) string {
return fmt.Sprintf("tracetest.agent-%s", serviceName)
}
func getResource(serviceName string) (*resource.Resource, error) {
hostname, err := os.Hostname()
if err != nil {
return nil, fmt.Errorf("could not get OS hostname: %w", err)
}
resource, err := resource.Merge(
resource.Default(),
resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String(serviceName),
semconv.HostName(hostname),
semconv.ServiceVersion(version.Version), // TODO: should we consider a version file for the agent?
),
)
if err != nil {
return nil, fmt.Errorf("could not merge resources: %w", err)
}
return resource, nil
}