Skip to content

Commit

Permalink
trace add resource update
Browse files Browse the repository at this point in the history
  • Loading branch information
reatang authored and kevwan committed Oct 23, 2023
1 parent 00db97f commit 2a9fc8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/trace/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
}

func startAgent(c Config) error {
AddResources(semconv.ServiceNameKey.String(c.Name))

opts := []sdktrace.TracerProviderOption{
// Set the sampling rate based on the parent span to 100%
sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(c.Sampler))),
// Record information about this application in a Resource.
sdktrace.WithResource(resource.NewSchemaless(semconv.ServiceNameKey.String(c.Name))),
sdktrace.WithResource(resource.NewSchemaless(attrResources...)),
}

if len(c.Endpoint) > 0 {
Expand Down
9 changes: 9 additions & 0 deletions core/trace/resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package trace

import "go.opentelemetry.io/otel/attribute"

var attrResources = make([]attribute.KeyValue, 0)

func AddResources(attrs ...attribute.KeyValue) {
attrResources = append(attrResources, attrs...)
}

0 comments on commit 2a9fc8d

Please sign in to comment.