@@ -292,7 +292,7 @@ func (s *Runner) Run(ctx context.Context) error {
292
292
}
293
293
}
294
294
295
- instrumentation , err := instrumentation . New (s .rawConfig , "apm-server" , version . Version )
295
+ instrumentation , err := newInstrumentation (s .rawConfig )
296
296
if err != nil {
297
297
return err
298
298
}
@@ -537,6 +537,50 @@ func (s *Runner) Run(ctx context.Context) error {
537
537
return errors .Join (result , closeErr )
538
538
}
539
539
540
+ // newInstrumentation is a thin wrapper around libbeat instrumentation that
541
+ // sets missing tracer configuration from elastic-agent.
542
+ func newInstrumentation (rawConfig * agentconfig.C ) (instrumentation.Instrumentation , error ) {
543
+ var apmCfg struct {
544
+ GlobalLabels string `config:"globallabels"`
545
+ TLS struct {
546
+ SkipVerify bool `config:"skipverify"`
547
+ ServerCertificate string `config:"servercert"`
548
+ ServerCA string `config:"serverca"`
549
+ } `config:"tls"`
550
+ }
551
+ cfg , err := rawConfig .Child ("instrumentation" , - 1 )
552
+ if err != nil {
553
+ // Fallback to instrumentation.New if the configs are not present.
554
+ return instrumentation .New (rawConfig , "apm-server" , version .Version )
555
+ }
556
+ if err := cfg .Unpack (& apmCfg ); err != nil {
557
+ return nil , err
558
+ }
559
+ const (
560
+ envVerifyServerCert = "ELASTIC_APM_VERIFY_SERVER_CERT"
561
+ envServerCert = "ELASTIC_APM_SERVER_CERT"
562
+ envCACert = "ELASTIC_APM_SERVER_CA_CERT_FILE"
563
+ envGlobalLabels = "ELASTIC_APM_GLOBAL_LABELS"
564
+ )
565
+ if apmCfg .TLS .SkipVerify {
566
+ os .Setenv (envVerifyServerCert , "false" )
567
+ defer os .Unsetenv (envVerifyServerCert )
568
+ }
569
+ if apmCfg .TLS .ServerCertificate != "" {
570
+ os .Setenv (envServerCert , apmCfg .TLS .ServerCertificate )
571
+ defer os .Unsetenv (envServerCert )
572
+ }
573
+ if apmCfg .TLS .ServerCA != "" {
574
+ os .Setenv (envCACert , apmCfg .TLS .ServerCA )
575
+ defer os .Unsetenv (envCACert )
576
+ }
577
+ if len (apmCfg .GlobalLabels ) > 0 {
578
+ os .Setenv (envGlobalLabels , apmCfg .GlobalLabels )
579
+ defer os .Unsetenv (envGlobalLabels )
580
+ }
581
+ return instrumentation .New (rawConfig , "apm-server" , version .Version )
582
+ }
583
+
540
584
func maxConcurrentDecoders (memLimitGB float64 ) uint {
541
585
// Allow 128 concurrent decoders for each 1GB memory, limited to at most 2048.
542
586
const max = 2048
0 commit comments