Skip to content

Commit

Permalink
fix(infra): add container id to service name of attribute metrics (#1684
Browse files Browse the repository at this point in the history
)

* feat(cd): edit iris dockerfile to run sh to get containerId
feat(infra): add containerId parameter on metric code

* fix(cd): add terraform init upgrade

* fix(chore): pnpm-lock resolve conflict

* fix(chore): pnpm-lock conflict resolve again

* fix(infra): add containerId to ServiceName attribute
  • Loading branch information
goathoon authored May 10, 2024
1 parent d8dbfde commit 7640905
Show file tree
Hide file tree
Showing 3 changed files with 9,410 additions and 12,016 deletions.
4 changes: 4 additions & 0 deletions apps/iris/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func main() {
if env == "production" {
// load container Id from args
containerId := os.Args[1]
if len(containerId) == 0 {
logProvider.Log(logger.ERROR, "Cannot find containerId Args")
}

if utils.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT_URL", "") != "" {
shutdown := observability.InitTracer(ctx)
defer shutdown()
Expand Down
6 changes: 4 additions & 2 deletions apps/iris/src/observability/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ func newMetricResource(containerId string) (*resource.Resource, error) {
resource.NewWithAttributes(semconv.SchemaURL,
semconv.ServiceName("iris-metric"),
semconv.ServiceVersion("0.1.0"),
semconv.ServiceInstanceID(getInstanceId()),
semconv.ContainerID(containerId),
semconv.ServiceInstanceID(concatString(getInstanceId(), containerId)),
))
}

func concatString(instanceId string, containerId string) string {
return instanceId + "-" + containerId
}
func newMeterProvider(res *resource.Resource, second time.Duration) (*sdkmetric.MeterProvider, error) {
// Use OLTP Exporter for Grafana Agent (Recommended)
entryPoint := os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT_URL")
Expand Down
Loading

0 comments on commit 7640905

Please sign in to comment.