janhoy commented on code in PR #5245:
URL: https://github.com/apache/solr/pull/5245#discussion_r4697321907


##########
solr/core/src/java/org/apache/solr/core/OpenTelemetryConfigurator.java:
##########
@@ -145,6 +180,146 @@ protected OpenTelemetry createOpenTelemetry() {
     return getOpenTelemetrySdk();
   }
 
+  /**
+   * The resource the configurator resolved for the OpenTelemetry it created, 
or {@code null} to let
+   * Solr derive one from the standard {@code OTEL_*} configuration. 
Overriding this is what keeps
+   * traces and metrics on an identical resource, including attributes 
contributed by {@code
+   * ResourceProvider} implementations that only the SDK knows about.
+   */
+  protected Resource getResource() {
+    return null;
+  }
+
+  /**
+   * Resource attributes describing this node, for any signal Solr exports 
itself. Reflects {@code
+   * OTEL_SERVICE_NAME} and {@code OTEL_RESOURCE_ATTRIBUTES} (or their {@code 
otel.*} system
+   * property equivalents), with Solr supplying {@code service.name}, {@code 
service.instance.id}
+   * and {@code host.name} where they are not configured.
+   */
+  public static Resource getTelemetryResource() {
+    return telemetryResource;
+  }
+
+  private static void adoptConfiguredResource(OpenTelemetryConfigurator 
configurator) {
+    Resource configured = configurator.getResource();
+    if (configured != null) {
+      telemetryResource = withSolrDefaults(configured);
+    }
+  }
+
+  /**
+   * Builds the resource from the standard OTEL configuration, for when no 
configurator supplies
+   * one: no {@code opentelemetry} module, or a Java agent owning tracing.
+   */
+  private static Resource resourceFromConfig(Map<String, String> env) {
+    AttributesBuilder attrs = Attributes.builder();
+    parseResourceAttributes(getConfig("OTEL_RESOURCE_ATTRIBUTES", 
env)).forEach(attrs::put);

Review Comment:
   Fixed in 4403d6a0898. The fallback resource now percent-decodes values, 
keeping `+` literal; the republished `otel.resource.attributes` stays encoded.



##########
solr/modules/opentelemetry/src/java/org/apache/solr/opentelemetry/OtelTracerConfigurator.java:
##########
@@ -57,33 +59,54 @@ public void init(NamedList<?> args) {
   public OpenTelemetry createOpenTelemetry() {
     // deliberately build() and not initialize(); the latter sets 
GlobalOpenTelemetry, which is
     // OpenTelemetryConfigurator's job
-    return 
AutoConfiguredOpenTelemetrySdk.builder().build().getOpenTelemetrySdk();
+    return AutoConfiguredOpenTelemetrySdk.builder()
+        // Solr owns the meter providers, and honours OTEL_METRICS_EXPORTER in 
its own OTLP exporter
+        .addPropertiesCustomizer(
+            config -> Map.of("otel.metrics.exporter", "none", 
"otel.logs.exporter", "none"))
+        // Hand the resolved resource back to Solr so its metrics carry the 
same one as these traces
+        .addResourceCustomizer(
+            (resource, config) -> {
+              this.resource = resource;
+              return resource;
+            })

Review Comment:
   Not changing the code. `ResourceProvider` extensions run before the capture 
and are covered; only a customizer provider that rewrites the resource is 
missed, and the SDK has no public accessor for the final resource. Documented 
the limit in fa0f74d49f7.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to