Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename EventEmitter and related classes to EventLogger #6316

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

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();
}
}