mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
Support for resource injection (#3383)
Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
parent
c2ff00883a
commit
e20ccdd011
@ -113,11 +113,13 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startAgent(c Config) error {
|
func startAgent(c Config) error {
|
||||||
|
AddResources(semconv.ServiceNameKey.String(c.Name))
|
||||||
|
|
||||||
opts := []sdktrace.TracerProviderOption{
|
opts := []sdktrace.TracerProviderOption{
|
||||||
// Set the sampling rate based on the parent span to 100%
|
// Set the sampling rate based on the parent span to 100%
|
||||||
sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(c.Sampler))),
|
sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(c.Sampler))),
|
||||||
// Record information about this application in a Resource.
|
// 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 {
|
if len(c.Endpoint) > 0 {
|
||||||
|
10
core/trace/resource.go
Normal file
10
core/trace/resource.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package trace
|
||||||
|
|
||||||
|
import "go.opentelemetry.io/otel/attribute"
|
||||||
|
|
||||||
|
var attrResources = make([]attribute.KeyValue, 0)
|
||||||
|
|
||||||
|
// AddResources add more resources in addition to configured trace name.
|
||||||
|
func AddResources(attrs ...attribute.KeyValue) {
|
||||||
|
attrResources = append(attrResources, attrs...)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user