Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions api/all/src/main/java/io/opentelemetry/api/OpenTelemetry.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.api;

import io.opentelemetry.api.logs.Logger;
import io.opentelemetry.api.logs.LoggerBuilder;
import io.opentelemetry.api.logs.LoggerProvider;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.api.metrics.MeterBuilder;
Expand Down Expand Up @@ -114,6 +116,18 @@ default MeterBuilder meterBuilder(String instrumentationScopeName) {
return getMeterProvider().meterBuilder(instrumentationScopeName);
}

default LoggerProvider getLoggerProvider() {
return LoggerProvider.noop();
}

default Logger getLogger(String instrumentationScopeName) {
return getLoggerProvider().get(instrumentationScopeName);
}

default LoggerBuilder getLoggerBuilder(String instrumentationScopeName) {
return getLoggerProvider().loggerBuilder(instrumentationScopeName);
}

/**
* Returns the {@link LoggerProvider} for bridging logs into OpenTelemetry.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ static Value<List<KeyValue>> of(Map<String, Value<?>> value) {
return KeyValueList.createFromMap(value);
}

static ValueMapBuilder mapBuilder() {
return new ValueMapBuilderImpl();
}

static ValueListBuilder listBuilder() {
return new ValueListBuilderImpl();
}

/** Returns the type of this {@link Value}. Useful for building switch statements. */
ValueType getType();

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

package io.opentelemetry.api.common;

public interface ValueListBuilder {

ValueListBuilder add(Value<?> value);

Value<?> build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.api.common;

import java.util.ArrayList;
import java.util.List;

class ValueListBuilderImpl implements ValueListBuilder {

private final List<Value<?>> values = new ArrayList<>();

@Override
public ValueListBuilder add(Value<?> value) {
values.add(value);
return this;
}

@Override
public Value<?> build() {
return Value.of(values.toArray(new Value<?>[0]));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.api.common;

public interface ValueMapBuilder {

default ValueMapBuilder put(String key, String value) {
put(key, Value.of(value));
return this;
}

default ValueMapBuilder put(String key, long value) {
put(key, Value.of(value));
return this;
}

default ValueMapBuilder put(String key, double value) {
put(key, Value.of(value));
return this;
}

default ValueMapBuilder put(String key, boolean value) {
put(key, Value.of(value));
return this;
}

ValueMapBuilder put(String key, Value<?> value);

Value<?> build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.api.common;

import java.util.ArrayList;
import java.util.List;

class ValueMapBuilderImpl implements ValueMapBuilder {

private final List<KeyValue> keyValues = new ArrayList<>();

@Override
public ValueMapBuilder put(String key, Value<?> value) {
keyValues.add(KeyValue.of(key, value));
return this;
}

@Override
public Value<?> build() {
return Value.of(keyValues.toArray(new KeyValue[0]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public LogRecordBuilder logRecordBuilder() {
return NOOP_LOG_RECORD_BUILDER;
}

@Override
public LogRecordBuilder eventBuilder(String eventName) {
return NOOP_LOG_RECORD_BUILDER;
}

private static final class NoopLogRecordBuilder implements LogRecordBuilder {

private NoopLogRecordBuilder() {}
Expand Down
13 changes: 13 additions & 0 deletions api/all/src/main/java/io/opentelemetry/api/logs/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,17 @@ public interface Logger {
* LogRecordBuilder#emit()}.
*/
LogRecordBuilder logRecordBuilder();

/**
* Return a {@link LogRecordBuilder} 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.
*/
default LogRecordBuilder eventBuilder(String eventName) {
return DefaultLogger.getInstance().eventBuilder(eventName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public LogRecordBuilder logRecordBuilder() {
return NOOP_LOG_RECORD_BUILDER;
}

@Override
public LogRecordBuilder eventBuilder(String eventName) {
return NOOP_LOG_RECORD_BUILDER;
}

private static final class NoopLogRecordBuilder implements ExtendedLogRecordBuilder {

private NoopLogRecordBuilder() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,21 @@ final class SdkLogRecordBuilder implements ExtendedLogRecordBuilder {
@Nullable private String severityText;
@Nullable private Value<?> body;
@Nullable private AttributesMap attributes;
@Nullable private final String eventName;

SdkLogRecordBuilder(
LoggerSharedState loggerSharedState, InstrumentationScopeInfo instrumentationScopeInfo) {
this(loggerSharedState, instrumentationScopeInfo, null);
}

SdkLogRecordBuilder(
LoggerSharedState loggerSharedState,
InstrumentationScopeInfo instrumentationScopeInfo,
@Nullable String eventName) {
this.loggerSharedState = loggerSharedState;
this.logLimits = loggerSharedState.getLogLimits();
this.instrumentationScopeInfo = instrumentationScopeInfo;
this.eventName = eventName;
}

@Override
Expand Down Expand Up @@ -133,6 +142,7 @@ public void emit() {
severity,
severityText,
body,
attributes));
attributes,
eventName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ static SdkLogRecordData create(
@Nullable String severityText,
@Nullable Value<?> body,
Attributes attributes,
int totalAttributeCount) {
int totalAttributeCount,
@Nullable String eventName) {
return new AutoValue_SdkLogRecordData(
resource,
instrumentationScopeInfo,
Expand All @@ -44,6 +45,7 @@ static SdkLogRecordData create(
severityText,
attributes,
totalAttributeCount,
eventName,
body);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public LogRecordBuilder logRecordBuilder() {
return NOOP_LOGGER.logRecordBuilder();
}

@Override
public LogRecordBuilder eventBuilder(String eventName) {
if (loggerEnabled) {
return new SdkLogRecordBuilder(loggerSharedState, instrumentationScopeInfo, eventName);
}
return NOOP_LOGGER.eventBuilder(eventName);
}

// VisibleForTesting
InstrumentationScopeInfo getInstrumentationScopeInfo() {
return instrumentationScopeInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SdkReadWriteLogRecord implements ReadWriteLogRecord {
private final Severity severity;
@Nullable private final String severityText;
@Nullable private final Value<?> body;
@Nullable private final String eventName;
private final Object lock = new Object();

@GuardedBy("lock")
Expand All @@ -46,7 +47,8 @@ private SdkReadWriteLogRecord(
Severity severity,
@Nullable String severityText,
@Nullable Value<?> body,
@Nullable AttributesMap attributes) {
@Nullable AttributesMap attributes,
@Nullable String eventName) {
this.logLimits = logLimits;
this.resource = resource;
this.instrumentationScopeInfo = instrumentationScopeInfo;
Expand All @@ -57,6 +59,7 @@ private SdkReadWriteLogRecord(
this.severityText = severityText;
this.body = body;
this.attributes = attributes;
this.eventName = eventName;
}

/** Create the log record with the given configuration. */
Expand All @@ -70,7 +73,8 @@ static SdkReadWriteLogRecord create(
Severity severity,
@Nullable String severityText,
@Nullable Value<?> body,
@Nullable AttributesMap attributes) {
@Nullable AttributesMap attributes,
@Nullable String eventName) {
return new SdkReadWriteLogRecord(
logLimits,
resource,
Expand All @@ -81,7 +85,8 @@ static SdkReadWriteLogRecord create(
severity,
severityText,
body,
attributes);
attributes,
eventName);
}

@Override
Expand Down Expand Up @@ -122,7 +127,8 @@ public LogRecordData toLogRecordData() {
severityText,
body,
getImmutableAttributes(),
attributes == null ? 0 : attributes.getTotalAddedValues());
attributes == null ? 0 : attributes.getTotalAddedValues(),
eventName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@ default Value<?> getBodyValue() {
* LogLimits#getMaxNumberOfAttributes()}.
*/
int getTotalAttributeCount();

@Nullable
String getEventName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ SdkReadWriteLogRecord buildLogRecord() {
Severity.DEBUG,
"buggin",
body,
initialAttributes);
initialAttributes,
null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,7 @@ public Builder setBody(io.opentelemetry.sdk.logs.data.Body body) {

/** Set the total attribute count. */
public abstract Builder setTotalAttributeCount(int totalAttributeCount);

public abstract Builder setEventName(String eventName);
}
}