|
72 | 72 | import datadog.trace.civisibility.interceptor.CiVisibilityTraceInterceptor; |
73 | 73 | import datadog.trace.common.GitMetadataTraceInterceptor; |
74 | 74 | import datadog.trace.common.metrics.MetricsAggregator; |
| 75 | +import datadog.trace.common.metrics.NoOpMetricsAggregator; |
75 | 76 | import datadog.trace.common.sampling.Sampler; |
76 | 77 | import datadog.trace.common.sampling.SingleSpanSampler; |
77 | 78 | import datadog.trace.common.sampling.SpanSamplingRules; |
@@ -182,7 +183,7 @@ public static CoreTracerBuilder builder() { |
182 | 183 | /** Scope manager is in charge of managing the scopes from which spans are created */ |
183 | 184 | final ContinuableScopeManager scopeManager; |
184 | 185 |
|
185 | | - final MetricsAggregator metricsAggregator; |
| 186 | + volatile MetricsAggregator metricsAggregator; |
186 | 187 |
|
187 | 188 | /** Initial static configuration associated with the tracer. */ |
188 | 189 | final Config initialConfig; |
@@ -783,14 +784,26 @@ private CoreTracer( |
783 | 784 | pendingTraceBuffer.start(); |
784 | 785 |
|
785 | 786 | sharedCommunicationObjects.whenReady(this.writer::start); |
786 | | - |
787 | | - metricsAggregator = |
788 | | - createMetricsAggregator(config, sharedCommunicationObjects, this.healthMetrics); |
789 | | - // Schedule the metrics aggregator to begin reporting after a random delay of 1 to 10 seconds |
790 | | - // (using milliseconds granularity.) This avoids a fleet of traced applications starting at the |
791 | | - // same time from sending metrics in sync. |
792 | | - AgentTaskScheduler.get() |
793 | | - .scheduleWithJitter(MetricsAggregator::start, metricsAggregator, 1, SECONDS); |
| 787 | + // temporary assign a no-op instance. The final one will be resolved when the discovery will be |
| 788 | + // allowed |
| 789 | + metricsAggregator = NoOpMetricsAggregator.INSTANCE; |
| 790 | + final SharedCommunicationObjects sco = sharedCommunicationObjects; |
| 791 | + // asynchronously create the aggregator to avoid triggering expensive classloading during the |
| 792 | + // tracer initialisation. |
| 793 | + sharedCommunicationObjects.whenReady( |
| 794 | + () -> |
| 795 | + AgentTaskScheduler.get() |
| 796 | + .execute( |
| 797 | + () -> { |
| 798 | + metricsAggregator = createMetricsAggregator(config, sco, this.healthMetrics); |
| 799 | + // Schedule the metrics aggregator to begin reporting after a random delay of |
| 800 | + // 1 to 10 seconds (using milliseconds granularity.) |
| 801 | + // This avoids a fleet of traced applications starting at the same time from |
| 802 | + // sending metrics in sync. |
| 803 | + AgentTaskScheduler.get() |
| 804 | + .scheduleWithJitter( |
| 805 | + MetricsAggregator::start, metricsAggregator, 1, SECONDS); |
| 806 | + })); |
794 | 807 |
|
795 | 808 | if (dataStreamsMonitoring == null) { |
796 | 809 | this.dataStreamsMonitoring = |
|
0 commit comments