From 34b64b1f772f9e6d3874470e86713fc4675abbd1 Mon Sep 17 00:00:00 2001 From: jason plumb <75337021+breedx-splk@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:27:33 -0700 Subject: [PATCH] Remove domain from event api. (#6253) Co-authored-by: Trask Stalnaker --- .../events/DefaultEventEmitterProvider.java | 5 -- .../api/events/EventEmitter.java | 4 +- .../api/events/EventEmitterBuilder.java | 9 ---- .../DefaultEventEmitterProviderTest.java | 1 - .../api/events/DefaultEventEmitterTest.java | 6 ++- .../OtlpExporterIntegrationTest.java | 5 -- .../sdk/autoconfigure/FullConfigTest.java | 9 +--- .../sdk/logs/internal/SdkEventBuilder.java | 6 +-- .../internal/SdkEventEmitterProvider.java | 28 +++-------- .../logs/internal/SdkEventBuilderTest.java | 8 ++-- .../internal/SdkEventEmitterProviderTest.java | 46 ++----------------- 11 files changed, 23 insertions(+), 104 deletions(-) diff --git a/api/events/src/main/java/io/opentelemetry/api/events/DefaultEventEmitterProvider.java b/api/events/src/main/java/io/opentelemetry/api/events/DefaultEventEmitterProvider.java index 2f5b69826fd..59f75872fa1 100644 --- a/api/events/src/main/java/io/opentelemetry/api/events/DefaultEventEmitterProvider.java +++ b/api/events/src/main/java/io/opentelemetry/api/events/DefaultEventEmitterProvider.java @@ -34,11 +34,6 @@ public EventEmitterBuilder setInstrumentationVersion(String instrumentationVersi return this; } - @Override - public EventEmitterBuilder setEventDomain(String eventDomain) { - return this; - } - @Override public EventEmitter build() { return DefaultEventEmitter.getInstance(); diff --git a/api/events/src/main/java/io/opentelemetry/api/events/EventEmitter.java b/api/events/src/main/java/io/opentelemetry/api/events/EventEmitter.java index a8dc47c83d7..395fa4e53e5 100644 --- a/api/events/src/main/java/io/opentelemetry/api/events/EventEmitter.java +++ b/api/events/src/main/java/io/opentelemetry/api/events/EventEmitter.java @@ -15,8 +15,8 @@ * *
{@code
  * class MyClass {
- *   private final EventEmitter eventEmitter = openTelemetryEventEmitterProvider.eventEmitterBuilder("scope-name")
- *         .setEventDomain("acme.observability")
+ *   private final EventEmitter eventEmitter = openTelemetryEventEmitterProvider
+ *         .eventEmitterBuilder("scope-name")
  *         .build();
  *
  *   void doWork() {
diff --git a/api/events/src/main/java/io/opentelemetry/api/events/EventEmitterBuilder.java b/api/events/src/main/java/io/opentelemetry/api/events/EventEmitterBuilder.java
index 0aa67a25b08..0bdb9e2f57e 100644
--- a/api/events/src/main/java/io/opentelemetry/api/events/EventEmitterBuilder.java
+++ b/api/events/src/main/java/io/opentelemetry/api/events/EventEmitterBuilder.java
@@ -14,15 +14,6 @@
  */
 public interface EventEmitterBuilder {
 
-  /**
-   * Sets the event domain. Event domain is not part of {@link EventEmitter} identity.
-   *
-   * @param eventDomain The event domain, which acts as a namespace for event names. Within a
-   *     particular event domain, event name defines a particular class or type of event.
-   * @return this
-   */
-  EventEmitterBuilder setEventDomain(String eventDomain);
-
   /**
    * Set the scope schema URL of the resulting {@link EventEmitter}. Schema URL is part of {@link
    * EventEmitter} identity.
diff --git a/api/events/src/test/java/io/opentelemetry/api/events/DefaultEventEmitterProviderTest.java b/api/events/src/test/java/io/opentelemetry/api/events/DefaultEventEmitterProviderTest.java
index 33651e89c6e..04c5cc83e86 100644
--- a/api/events/src/test/java/io/opentelemetry/api/events/DefaultEventEmitterProviderTest.java
+++ b/api/events/src/test/java/io/opentelemetry/api/events/DefaultEventEmitterProviderTest.java
@@ -23,7 +23,6 @@ void noopEventEmitterProvider_doesNotThrow() {
             () ->
                 provider
                     .eventEmitterBuilder("scope-name")
-                    .setEventDomain("event-domain")
                     .setInstrumentationVersion("1.0")
                     .setSchemaUrl("http://schema.com")
                     .build())
diff --git a/api/events/src/test/java/io/opentelemetry/api/events/DefaultEventEmitterTest.java b/api/events/src/test/java/io/opentelemetry/api/events/DefaultEventEmitterTest.java
index 460cb1583ac..324680d13d6 100644
--- a/api/events/src/test/java/io/opentelemetry/api/events/DefaultEventEmitterTest.java
+++ b/api/events/src/test/java/io/opentelemetry/api/events/DefaultEventEmitterTest.java
@@ -21,7 +21,9 @@ void emit() {
     assertThatCode(
             () ->
                 DefaultEventEmitter.getInstance()
-                    .emit("event-name", Attributes.builder().put("key1", "value1").build()))
+                    .emit(
+                        "event-domain.event-name",
+                        Attributes.builder().put("key1", "value1").build()))
         .doesNotThrowAnyException();
   }
 
@@ -32,7 +34,7 @@ void builder() {
     assertThatCode(
             () ->
                 emitter
-                    .builder("myEvent", attributes)
+                    .builder("com.example.MyEvent", attributes)
                     .setTimestamp(123456L, TimeUnit.NANOSECONDS)
                     .setTimestamp(Instant.now())
                     .emit())
diff --git a/integration-tests/otlp/src/main/java/io/opentelemetry/integrationtest/OtlpExporterIntegrationTest.java b/integration-tests/otlp/src/main/java/io/opentelemetry/integrationtest/OtlpExporterIntegrationTest.java
index 271409e8ea3..30ab713b118 100644
--- a/integration-tests/otlp/src/main/java/io/opentelemetry/integrationtest/OtlpExporterIntegrationTest.java
+++ b/integration-tests/otlp/src/main/java/io/opentelemetry/integrationtest/OtlpExporterIntegrationTest.java
@@ -536,7 +536,6 @@ private static void testLogRecordExporter(LogRecordExporter logRecordExporter) {
     EventEmitter eventEmitter =
         SdkEventEmitterProvider.create(loggerProvider)
             .eventEmitterBuilder(OtlpExporterIntegrationTest.class.getName())
-            .setEventDomain("event-domain")
             .build();
 
     SpanContext spanContext =
@@ -712,10 +711,6 @@ private static void testLogRecordExporter(LogRecordExporter logRecordExporter) {
     assertThat(protoLog2.getBody().getStringValue()).isEmpty();
     assertThat(protoLog2.getAttributesList())
         .containsExactlyInAnyOrder(
-            KeyValue.newBuilder()
-                .setKey("event.domain")
-                .setValue(AnyValue.newBuilder().setStringValue("event-domain").build())
-                .build(),
             KeyValue.newBuilder()
                 .setKey("event.name")
                 .setValue(AnyValue.newBuilder().setStringValue("event-name").build())
diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FullConfigTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FullConfigTest.java
index affe5d4fd63..3015339f71e 100644
--- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FullConfigTest.java
+++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FullConfigTest.java
@@ -207,10 +207,7 @@ void configures() throws Exception {
     logger.logRecordBuilder().setBody("info log message").setSeverity(Severity.INFO).emit();
 
     EventEmitter eventEmitter =
-        GlobalEventEmitterProvider.get()
-            .eventEmitterBuilder("test")
-            .setEventDomain("test-domain")
-            .build();
+        GlobalEventEmitterProvider.get().eventEmitterBuilder("test").build();
     eventEmitter.emit("test-name", Attributes.builder().put("cow", "moo").build());
 
     openTelemetrySdk.getSdkTracerProvider().forceFlush().join(10, TimeUnit.SECONDS);
@@ -336,10 +333,6 @@ void configures() throws Exception {
             logRecord ->
                 assertThat(logRecord.getAttributesList())
                     .containsExactlyInAnyOrder(
-                        KeyValue.newBuilder()
-                            .setKey("event.domain")
-                            .setValue(AnyValue.newBuilder().setStringValue("test-domain").build())
-                            .build(),
                         KeyValue.newBuilder()
                             .setKey("event.name")
                             .setValue(AnyValue.newBuilder().setStringValue("test-name").build())
diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilder.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilder.java
index a79b09babc3..aefa6832242 100644
--- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilder.java
+++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilder.java
@@ -12,12 +12,10 @@
 
 class SdkEventBuilder implements EventBuilder {
   private final LogRecordBuilder logRecordBuilder;
-  private final String eventDomain;
   private final String eventName;
 
-  SdkEventBuilder(LogRecordBuilder logRecordBuilder, String eventDomain, String eventName) {
+  SdkEventBuilder(LogRecordBuilder logRecordBuilder, String eventName) {
     this.logRecordBuilder = logRecordBuilder;
-    this.eventDomain = eventDomain;
     this.eventName = eventName;
   }
 
@@ -35,7 +33,7 @@ public EventBuilder setTimestamp(Instant instant) {
 
   @Override
   public void emit() {
-    SdkEventEmitterProvider.addEventNameAndDomain(logRecordBuilder, eventDomain, eventName);
+    SdkEventEmitterProvider.addEventName(logRecordBuilder, eventName);
     logRecordBuilder.emit();
   }
 }
diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/SdkEventEmitterProvider.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/SdkEventEmitterProvider.java
index 1cc6768667e..885f46f7e94 100644
--- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/SdkEventEmitterProvider.java
+++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/SdkEventEmitterProvider.java
@@ -26,11 +26,8 @@
  */
 public final class SdkEventEmitterProvider implements EventEmitterProvider {
 
-  static final AttributeKey EVENT_DOMAIN = AttributeKey.stringKey("event.domain");
   static final AttributeKey EVENT_NAME = AttributeKey.stringKey("event.name");
 
-  static final String DEFAULT_EVENT_DOMAIN = "unknown";
-
   private final LoggerProvider delegateLoggerProvider;
   private final Clock clock;
 
@@ -55,9 +52,7 @@ public static SdkEventEmitterProvider create(LoggerProvider delegateLoggerProvid
 
   @Override
   public EventEmitter get(String instrumentationScopeName) {
-    return eventEmitterBuilder(instrumentationScopeName)
-        .setEventDomain(DEFAULT_EVENT_DOMAIN)
-        .build();
+    return eventEmitterBuilder(instrumentationScopeName).build();
   }
 
   @Override
@@ -70,19 +65,12 @@ private static class SdkEventEmitterBuilder implements EventEmitterBuilder {
 
     private final Clock clock;
     private final LoggerBuilder delegateLoggerBuilder;
-    private String eventDomain = DEFAULT_EVENT_DOMAIN;
 
     private SdkEventEmitterBuilder(Clock clock, LoggerBuilder delegateLoggerBuilder) {
       this.clock = clock;
       this.delegateLoggerBuilder = delegateLoggerBuilder;
     }
 
-    @Override
-    public EventEmitterBuilder setEventDomain(String eventDomain) {
-      this.eventDomain = eventDomain;
-      return this;
-    }
-
     @Override
     public EventEmitterBuilder setSchemaUrl(String schemaUrl) {
       delegateLoggerBuilder.setSchemaUrl(schemaUrl);
@@ -97,7 +85,7 @@ public EventEmitterBuilder setInstrumentationVersion(String instrumentationScope
 
     @Override
     public EventEmitter build() {
-      return new SdkEventEmitter(clock, delegateLoggerBuilder.build(), eventDomain);
+      return new SdkEventEmitter(clock, delegateLoggerBuilder.build());
     }
   }
 
@@ -105,12 +93,10 @@ private static class SdkEventEmitter implements EventEmitter {
 
     private final Clock clock;
     private final Logger delegateLogger;
-    private final String eventDomain;
 
-    private SdkEventEmitter(Clock clock, Logger delegateLogger, String eventDomain) {
+    private SdkEventEmitter(Clock clock, Logger delegateLogger) {
       this.clock = clock;
       this.delegateLogger = delegateLogger;
-      this.eventDomain = eventDomain;
     }
 
     @Override
@@ -120,7 +106,6 @@ public EventBuilder builder(String eventName, Attributes attributes) {
               .logRecordBuilder()
               .setTimestamp(clock.now(), TimeUnit.NANOSECONDS)
               .setAllAttributes(attributes),
-          eventDomain,
           eventName);
     }
 
@@ -131,13 +116,12 @@ public void emit(String eventName, Attributes attributes) {
               .logRecordBuilder()
               .setTimestamp(clock.now(), TimeUnit.NANOSECONDS)
               .setAllAttributes(attributes);
-      addEventNameAndDomain(logRecordBuilder, eventDomain, eventName);
+      addEventName(logRecordBuilder, eventName);
       logRecordBuilder.emit();
     }
   }
 
-  static void addEventNameAndDomain(
-      LogRecordBuilder logRecordBuilder, String eventDomain, String eventName) {
-    logRecordBuilder.setAttribute(EVENT_DOMAIN, eventDomain).setAttribute(EVENT_NAME, eventName);
+  static void addEventName(LogRecordBuilder logRecordBuilder, String eventName) {
+    logRecordBuilder.setAttribute(EVENT_NAME, eventName);
   }
 }
diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilderTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilderTest.java
index 2115463a771..e53fd6549a9 100644
--- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilderTest.java
+++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilderTest.java
@@ -8,7 +8,10 @@
 import static io.opentelemetry.api.common.AttributeKey.stringKey;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -21,7 +24,6 @@ class SdkEventBuilderTest {
 
   @Test
   void emit() {
-    String eventDomain = "mydomain";
     String eventName = "banana";
 
     LogRecordBuilder logRecordBuilder = mock(LogRecordBuilder.class);
@@ -29,11 +31,11 @@ void emit() {
     when(logRecordBuilder.setAttribute(any(), any())).thenReturn(logRecordBuilder);
 
     Instant instant = Instant.now();
-    new SdkEventBuilder(logRecordBuilder, eventDomain, eventName)
+    new SdkEventBuilder(logRecordBuilder, eventName)
         .setTimestamp(123456L, TimeUnit.NANOSECONDS)
         .setTimestamp(instant)
         .emit();
-    verify(logRecordBuilder).setAttribute(stringKey("event.domain"), eventDomain);
+    verify(logRecordBuilder, never()).setAttribute(eq(stringKey("event.domain")), anyString());
     verify(logRecordBuilder).setAttribute(stringKey("event.name"), eventName);
     verify(logRecordBuilder).setTimestamp(123456L, TimeUnit.NANOSECONDS);
     verify(logRecordBuilder).setTimestamp(instant);
diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventEmitterProviderTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventEmitterProviderTest.java
index 7f22b1376a8..bf7e58ddc5f 100644
--- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventEmitterProviderTest.java
+++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventEmitterProviderTest.java
@@ -37,12 +37,11 @@ class SdkEventEmitterProviderTest {
           clock);
 
   @Test
-  void emit_WithDomain() {
+  void emit() {
     when(clock.now()).thenReturn(10L);
 
     eventEmitterProvider
         .eventEmitterBuilder("test-scope")
-        .setEventDomain("event-domain")
         .build()
         .emit(
             "event-name",
@@ -50,8 +49,6 @@ void emit_WithDomain() {
                 .put("key1", "value1")
                 // should be overridden by the eventName argument passed to emit
                 .put("event.name", "foo")
-                // should be overridden by the eventDomain
-                .put("event.domain", "foo")
                 .build());
 
     assertThat(seenLog.get().toLogRecordData())
@@ -59,40 +56,7 @@ void emit_WithDomain() {
         .hasInstrumentationScope(InstrumentationScopeInfo.create("test-scope"))
         .hasTimestamp(10L)
         .hasAttributes(
-            Attributes.builder()
-                .put("key1", "value1")
-                .put("event.domain", "event-domain")
-                .put("event.name", "event-name")
-                .build());
-  }
-
-  @Test
-  void emit_NoDomain() {
-    when(clock.now()).thenReturn(10L);
-
-    eventEmitterProvider
-        .eventEmitterBuilder("test-scope")
-        .build()
-        .emit(
-            "event-name",
-            Attributes.builder()
-                .put("key1", "value1")
-                // should be overridden by the eventName argument passed to emit
-                .put("event.name", "foo")
-                // should be overridden by the default eventDomain
-                .put("event.domain", "foo")
-                .build());
-
-    assertThat(seenLog.get().toLogRecordData())
-        .hasResource(RESOURCE)
-        .hasInstrumentationScope(InstrumentationScopeInfo.create("test-scope"))
-        .hasTimestamp(10L)
-        .hasAttributes(
-            Attributes.builder()
-                .put("key1", "value1")
-                .put("event.domain", "unknown")
-                .put("event.name", "event-name")
-                .build());
+            Attributes.builder().put("key1", "value1").put("event.name", "event-name").build());
   }
 
   @Test
@@ -111,10 +75,6 @@ private void verifySeen(long timestamp, Attributes attributes) {
         .hasResource(RESOURCE)
         .hasInstrumentationScope(InstrumentationScopeInfo.create("test-scope"))
         .hasTimestamp(timestamp)
-        .hasAttributes(
-            attributes.toBuilder()
-                .put("event.domain", "unknown")
-                .put("event.name", "testing")
-                .build());
+        .hasAttributes(attributes.toBuilder().put("event.name", "testing").build());
   }
 }