Skip to content

Commit

Permalink
Rename EventEmitter and related classes to EventLogger (#6316)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored Mar 26, 2024
1 parent b897510 commit 13ea334
Show file tree
Hide file tree
Showing 23 changed files with 341 additions and 338 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import java.time.Instant;
import java.util.concurrent.TimeUnit;

class DefaultEventEmitter implements EventEmitter {
class DefaultEventLogger implements EventLogger {

private static final EventEmitter INSTANCE = new DefaultEventEmitter();
private static final EventLogger INSTANCE = new DefaultEventLogger();

private DefaultEventEmitter() {}
private DefaultEventLogger() {}

static EventEmitter getInstance() {
static EventLogger getInstance() {
return INSTANCE;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.api.incubator.events;

class DefaultEventLoggerProvider implements EventLoggerProvider {

private static final EventLoggerProvider INSTANCE = new DefaultEventLoggerProvider();
private static final EventLoggerBuilder NOOP_EVENT_LOGGER_BUILDER = new NoopEventLoggerBuilder();

private DefaultEventLoggerProvider() {}

static EventLoggerProvider getInstance() {
return INSTANCE;
}

@Override
public EventLoggerBuilder eventLoggerBuilder(String instrumentationScopeName) {
return NOOP_EVENT_LOGGER_BUILDER;
}

private static class NoopEventLoggerBuilder implements EventLoggerBuilder {

@Override
public EventLoggerBuilder setSchemaUrl(String schemaUrl) {
return this;
}

@Override
public EventLoggerBuilder setInstrumentationVersion(String instrumentationVersion) {
return this;
}

@Override
public EventLogger build() {
return DefaultEventLogger.getInstance();
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.api.incubator.events;

import io.opentelemetry.api.common.Attributes;
import javax.annotation.concurrent.ThreadSafe;

/**
* A {@link EventLogger} is the entry point into an event pipeline.
*
* <p>Example usage emitting events:
*
* <pre>{@code
* class MyClass {
* private final EventLogger eventLogger = eventLoggerProvider
* .eventLoggerBuilder("scope-name")
* .build();
*
* void doWork() {
* eventLogger.emit("my-namespace.my-event", Attributes.builder()
* .put("key1", "value1")
* .put("key2", "value2")
* .build())
* // do work
* }
* }
* }</pre>
*/
@ThreadSafe
public interface EventLogger {

/**
* Emit an event.
*
* @param eventName the event name, which identifies the class or type of event. Event with the
* same name are structurally similar to one another. Event names are subject to the same
* naming rules as attribute names. Notably, they are namespaced to avoid collisions. See <a
* href="https://opentelemetry.io/docs/specs/semconv/general/events/">event.name semantic
* conventions</a> for more details.
* @param attributes attributes associated with the event
*/
void emit(String eventName, Attributes attributes);

/**
* Return a {@link EventBuilder} to emit an event.
*
* @param eventName the event name, which identifies the class or type of event. Event with the
* same name are structurally similar to one another. Event names are subject to the same
* naming rules as attribute names. Notably, they are namespaced to avoid collisions. See <a
* href="https://opentelemetry.io/docs/specs/semconv/general/events/">event.name semantic
* conventions</a> for more details.
* @param attributes attributes associated with the event
*/
EventBuilder builder(String eventName, Attributes attributes);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.api.incubator.events;

/**
* Builder class for creating {@link EventLogger} instances.
*
* <p>{@link EventLogger}s are identified by their scope name, version, and schema URL. These
* identifying fields, along with attributes, combine to form the instrumentation scope, which is
* attached to all events produced by the {@link EventLogger}.
*/
public interface EventLoggerBuilder {

/**
* Set the scope schema URL of the resulting {@link EventLogger}. Schema URL is part of {@link
* EventLogger} identity.
*
* @param schemaUrl The schema URL.
* @return this
*/
EventLoggerBuilder setSchemaUrl(String schemaUrl);

/**
* Sets the instrumentation scope version of the resulting {@link EventLogger}. Version is part of
* {@link EventLogger} identity.
*
* @param instrumentationScopeVersion The instrumentation scope version.
* @return this
*/
EventLoggerBuilder setInstrumentationVersion(String instrumentationScopeVersion);

/**
* Gets or creates a {@link EventLogger} instance.
*
* @return a {@link EventLogger} instance configured with the provided options.
*/
EventLogger build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,38 @@
import javax.annotation.concurrent.ThreadSafe;

/**
* A registry for creating scoped {@link EventEmitter}s. The name <i>Provider</i> is for consistency
* A registry for creating scoped {@link EventLogger}s. The name <i>Provider</i> is for consistency
* with other languages and it is <b>NOT</b> loaded using reflection.
*
* @see EventEmitter
* @see EventLogger
*/
@ThreadSafe
public interface EventEmitterProvider {
public interface EventLoggerProvider {

/**
* Gets or creates a named EventEmitter instance which emits events to the {@code eventDomain}.
* Gets or creates a named {@link EventLogger} instance.
*
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
* the instrumentation library, package, or fully qualified class name. Must not be null.
* @return a Logger instance.
*/
default EventEmitter get(String instrumentationScopeName) {
return eventEmitterBuilder(instrumentationScopeName).build();
default EventLogger get(String instrumentationScopeName) {
return eventLoggerBuilder(instrumentationScopeName).build();
}

/**
* Creates a LoggerBuilder for a named EventEmitter instance.
* Creates a LoggerBuilder for a named {@link EventLogger} instance.
*
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
* the instrumentation library, package, or fully qualified class name. Must not be null.
* @return a LoggerBuilder instance.
*/
EventEmitterBuilder eventEmitterBuilder(String instrumentationScopeName);
EventLoggerBuilder eventLoggerBuilder(String instrumentationScopeName);

/**
* Returns a no-op {@link EventEmitterProvider} which provides Loggers which do not record or
* emit.
* Returns a no-op {@link EventLoggerProvider} which provides Loggers which do not record or emit.
*/
static EventEmitterProvider noop() {
return DefaultEventEmitterProvider.getInstance();
static EventLoggerProvider noop() {
return DefaultEventLoggerProvider.getInstance();
}
}
Loading

0 comments on commit 13ea334

Please sign in to comment.