@@ -59,16 +59,36 @@ type Config struct {
5959 // Default: ""
6060 // Example: "v1.2.3"
6161 Release string
62+
63+ // ResourceAttributes is custom resource attributes (Optional)
64+ ResourceAttributes map [string ]string
6265}
6366
6467func NewApmplusHandler (cfg * Config ) (handler callbacks.Handler , shutdown func (ctx context.Context ) error , err error ) {
65- p , err := opentelemetry .NewOpenTelemetryProvider (
68+ resourceAttributes := []attribute.KeyValue {
69+ attribute .String ("apmplus.business_type" , "gen_ai" ),
70+ }
71+ if len (cfg .ResourceAttributes ) > 0 {
72+ for k , v := range cfg .ResourceAttributes {
73+ resourceAttributes = append (resourceAttributes , attribute .String (k , v ))
74+ }
75+ }
76+ var resourceOpts []opentelemetry.Option
77+ for _ , attr := range resourceAttributes {
78+ resourceOpts = append (resourceOpts ,
79+ opentelemetry .WithResourceAttribute (attr ),
80+ )
81+ }
82+
83+ providerOpts := []opentelemetry.Option {
6684 opentelemetry .WithServiceName (cfg .ServiceName ),
6785 opentelemetry .WithExportEndpoint (cfg .Host ),
6886 opentelemetry .WithInsecure (),
6987 opentelemetry .WithHeaders (map [string ]string {"x-byteapm-appkey" : cfg .AppKey }),
70- opentelemetry .WithResourceAttribute (attribute .String ("apmplus.business_type" , "gen_ai" )),
71- )
88+ }
89+ providerOpts = append (providerOpts , resourceOpts ... )
90+
91+ p , err := opentelemetry .NewOpenTelemetryProvider (providerOpts ... )
7292 if p == nil || err != nil {
7393 return nil , nil , errors .New ("init opentelemetry provider failed" )
7494 }
0 commit comments