11// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
22package com .yahoo .vespa .model .container ;
33
4+ import ai .vespa .telemetry .TelemetryConfig ;
45import com .yahoo .cloud .config .ClusterInfoConfig ;
56import com .yahoo .cloud .config .ConfigserverConfig ;
67import com .yahoo .cloud .config .CuratorConfig ;
1314import com .yahoo .config .model .producer .AnyConfigProducer ;
1415import com .yahoo .config .model .producer .TreeConfigProducer ;
1516import com .yahoo .config .provision .ClusterSpec ;
17+ import com .yahoo .config .provision .OpenTelemetryConfiguration ;
1618import com .yahoo .config .provision .Zone ;
1719import com .yahoo .container .ComponentsConfig ;
1820import com .yahoo .container .QrSearchersConfig ;
@@ -109,7 +111,8 @@ public abstract class ContainerCluster<CONTAINER extends Container>
109111 ClusterInfoConfig .Producer ,
110112 ConfigserverConfig .Producer ,
111113 CuratorConfig .Producer ,
112- SchemaInfoConfig .Producer
114+ SchemaInfoConfig .Producer ,
115+ TelemetryConfig .Producer
113116{
114117
115118 /**
@@ -168,6 +171,8 @@ public abstract class ContainerCluster<CONTAINER extends Container>
168171
169172 private volatile boolean deferChangesUntilRestart = false ;
170173 private final boolean applyOnRestartForApplicationMetadataConfigEnabled ;
174+ private final OpenTelemetryConfiguration opentelemetrySdk ;
175+ private final Map <String , String > telemetryResourceAttributes ;
171176 private boolean clientsLegacyMode ;
172177 private List <Client > clients = List .of ();
173178
@@ -179,7 +184,9 @@ public ContainerCluster(TreeConfigProducer<?> parent, String configSubId, String
179184 this .zooKeeperLocalhostAffinity = zooKeeperLocalhostAffinity ;
180185 this .compressionType = "zstd" ;
181186 applyOnRestartForApplicationMetadataConfigEnabled = deployState .featureFlags ().applyOnRestartForApplicationMetadataConfig ();
182-
187+ opentelemetrySdk = deployState .featureFlags ().opentelemetrySdk ();
188+ telemetryResourceAttributes = telemetryResourceAttributes (deployState , clusterId );
189+
183190 componentGroup = new ComponentGroup <>(this , "component" );
184191
185192 addCommonVespaBundles ();
@@ -199,6 +206,8 @@ public ContainerCluster(TreeConfigProducer<?> parent, String configSubId, String
199206 addSimpleComponent (com .yahoo .container .handler .ClustersStatus .class .getName ());
200207 addSimpleComponent ("com.yahoo.container.jdisc.DisabledConnectionLogProvider" );
201208 addSimpleComponent (com .yahoo .jdisc .http .server .jetty .Janitor .class );
209+ // OpenTelemetry tracing provider: present in all container types; hands out a no-op instance unless enabled.
210+ addSimpleComponent ("com.yahoo.container.jdisc.telemetry.OpenTelemetryProvider" );
202211 }
203212
204213 protected abstract boolean messageBusEnabled ();
@@ -566,6 +575,32 @@ public void getConfig(QrSearchersConfig.Builder builder) {
566575 if (containerSearch != null ) containerSearch .getConfig (builder );
567576 }
568577
578+ @ Override
579+ public void getConfig (TelemetryConfig .Builder builder ) {
580+ builder .enabled (opentelemetrySdk .enabled ())
581+ .endpoint (opentelemetrySdk .endpoint ())
582+ .samplingRatio (opentelemetrySdk .samplingRatio ());
583+ builder .resourceAttribute .putAll (telemetryResourceAttributes );
584+ }
585+
586+ /**
587+ * Resource attributes describing this container service, filled from the deployment identity available
588+ * in the model. Used by the OpenTelemetry provider to build the OTel {@code Resource}.
589+ */
590+ private Map <String , String > telemetryResourceAttributes (DeployState deployState , String clusterId ) {
591+ var applicationId = deployState .getProperties ().applicationId ();
592+
593+ Map <String , String > attributes = new LinkedHashMap <>();
594+ attributes .put ("application" , applicationId .application ().value ());
595+ attributes .put ("tenant" , applicationId .tenant ().value ());
596+ attributes .put ("zone" , this .zone .systemLocalValue ());
597+ attributes .put ("environment" , this .zone .environment ().value ());
598+ attributes .put ("cloud" , this .zone .cloud ().toString ());
599+ attributes .put ("cluster.type" , "container" );
600+ attributes .put ("cluster.id" , clusterId );
601+ return attributes ;
602+ }
603+
569604 @ Override
570605 public void getConfig (QrStartConfig .Builder builder ) {
571606 builder .jvm
0 commit comments