dimas-b commented on code in PR #2847:
URL: https://github.com/apache/polaris/pull/2847#discussion_r2449000927


##########
runtime/service/src/test/java/org/apache/polaris/service/tracing/TracingFilterTest.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.service.tracing;
+
+import static io.opentelemetry.api.common.AttributeKey.stringKey;
+import static io.restassured.RestAssured.given;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+import io.opentelemetry.api.common.AttributeKey;
+import io.opentelemetry.api.trace.SpanContext;
+import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter;
+import io.opentelemetry.sdk.trace.data.SpanData;
+import io.quarkus.test.common.http.TestHTTPEndpoint;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.http.ContentType;
+import jakarta.enterprise.inject.Produces;
+import jakarta.inject.Inject;
+import jakarta.inject.Singleton;
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+import org.apache.polaris.service.catalog.api.IcebergRestOAuth2Api;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+@TestProfile(TracingFilterTest.Profile.class)
+@TestHTTPEndpoint(IcebergRestOAuth2Api.class)
+@SuppressWarnings("UastIncorrectHttpHeaderInspection")
+public class TracingFilterTest {
+
+  public static class Profile implements QuarkusTestProfile {
+
+    @Produces
+    @Singleton
+    InMemorySpanExporter inMemorySpanExporter() {
+      return InMemorySpanExporter.create();
+    }
+
+    @Override
+    public Map<String, String> getConfigOverrides() {
+      return Map.of("quarkus.otel.sdk.disabled", "false");
+    }
+  }
+
+  @Inject InMemorySpanExporter inMemorySpanExporter;
+
+  @Test
+  void testW3CTraceContextPropagation() {
+
+    // Emulate an incoming request with a W3C trace context
+    // Example taken from:
+    // https://www.w3.org/TR/trace-context/#traceparent-header-field-values
+    String traceId = "4bf92f3577b34da6a3ce929d0e0e4736";
+    String spanId = "00f067aa0ba902b7";
+    String traceparent = "00-" + traceId + "-" + spanId + "-01";
+    String tracestate = "rojo=00f067aa0ba902b7,congo=t61rcWkgMzE";
+
+    given()
+        .contentType(ContentType.URLENC)
+        .formParam("grant_type", "client_credentials")
+        .formParam("scope", "PRINCIPAL_ROLE:ALL")
+        .formParam("client_id", "test-admin")
+        .formParam("client_secret", "test-secret")
+        // W3C headers
+        .header("traceparent", traceparent)
+        .header("tracestate", tracestate)
+        // Polaris correlation ID
+        .header("Polaris-Request-Id", "12345")
+        .when()
+        .post()
+        .then()
+        .statusCode(200);
+
+    List<SpanData> spans =
+        await()
+            .atMost(Duration.ofSeconds(30))
+            .until(inMemorySpanExporter::getFinishedSpanItems, sp -> 
!sp.isEmpty());
+
+    SpanData span = spans.getFirst();
+
+    Map<AttributeKey<?>, Object> attributes = span.getAttributes().asMap();
+    assertThat(attributes)
+        .containsEntry(stringKey(TracingFilter.REALM_ID_ATTRIBUTE), "POLARIS")
+        .containsEntry(stringKey(TracingFilter.REQUEST_ID_ATTRIBUTE), "12345");

Review Comment:
   side note: my thinking was to reuse request ID from OTel (e.g. trace ID + 
span ID). Since we're moving towards "correlation", I think it makes sense to 
integrate with the existing OTel standard. In that case it should not be 
necessary to add `REQUEST_ID_ATTRIBUTE` to the span, but someone inspecting the 
response headers would be able to correlate them to the trace.
   
   If OTel is present, what is the value of Polaris accepting / generating yet 
another request ID?
   
   Are we considering the Polaris request ID as a first class feature of the 
protocol (REST API flowing into Events) as opposed to a "helper" or 
"observability" feature?
   
   If OTel is not present, we can certainly generate a fresh request ID.



-- 
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]

Reply via email to