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

Reworking API for 1.0 and Java port #177

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ lazy val moneyCore =
Seq(
slf4j,
log4jbinding,
lombok,
metricsCore,
openTelemetryApi,
openTelemetrySemConv,
Expand Down Expand Up @@ -330,6 +331,7 @@ def javaOnlyProjectSettings = projectSettings ++ Seq(
)

def projectSettings = basicSettings ++ Seq(
compileOrder := CompileOrder.JavaThenScala,
ScoverageKeys.coverageHighlighting := true,
ScoverageKeys.coverageMinimum := 80,
ScoverageKeys.coverageFailOnMinimum := true,
Expand Down
3 changes: 3 additions & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config.stopBubbling = true
lombok.accessors.chain=true
lombok.accessors.fluent=true
60 changes: 60 additions & 0 deletions money-api/src/main/java/com/comcast/money/api/EventInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2012 Comcast Cable Communications Management, LLC
*
* Licensed 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 com.comcast.money.api;

import java.util.concurrent.TimeUnit;

import io.opentelemetry.api.common.Attributes;

/**
* An event that was recorded on a {@link Span}.
*/
public interface EventInfo {
/**
* @return the name of the event
*/
String name();

/**
* @return the attributes recorded on the event
*/
Attributes attributes();

/**
* @return the timestamp of when the event occurred in nanoseconds since the epoch
*/
long timestampNanos();

/**
* @return the timestamp of when the event occurred in microseconds since the epoch
*/
default long timestampMicros() {
return TimeUnit.NANOSECONDS.toMicros(timestampNanos());
}

/**
* @return the timestamp of when the event occurred in milliseconds since the epoch
*/
default long timestampMillis() {
return TimeUnit.NANOSECONDS.toMillis(timestampNanos());
}

/**
* @return an exception if one was recorded with the event; otherwise {@code null}
*/
Throwable exception();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class IdGenerator {
public final class IdGenerator {
private IdGenerator() { }

public static final String INVALID_TRACE_ID = "00000000-0000-0000-0000-000000000000";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.Objects;

public class InstrumentationLibrary {
public final class InstrumentationLibrary {
public static final InstrumentationLibrary UNKNOWN = new InstrumentationLibrary("unknown");

private final String name;
Expand Down
153 changes: 153 additions & 0 deletions money-api/src/main/java/com/comcast/money/api/InvalidSpan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright 2012 Comcast Cable Communications Management, LLC
*
* Licensed 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 com.comcast.money.api;

import java.util.concurrent.TimeUnit;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Scope;

enum InvalidSpan implements Span, SpanInfo {
INSTANCE;

// $COVERAGE-OFF$
@Override
public Span addEvent(String name, Attributes attributes) {
return this;
}

@Override
public Span addEvent(String name, Attributes attributes, long timestamp, TimeUnit unit) {
return this;
}

@Override
public Span setStatus(StatusCode canonicalCode, String description) {
return this;
}

@Override
public Span recordException(Throwable exception, Attributes additionalAttributes) {
return this;
}

@Override
public Span updateName(String name) {
return this;
}

@Override
public void end() { }

@Override
public void end(long timestamp, TimeUnit unit) { }

@Override
public SpanContext getSpanContext() {
return SpanId.getInvalid().toSpanContext();
}

@Override
public long startTimeNanos() {
return 0L;
}

@Override
public boolean hasEnded() {
return false;
}

@Override
public long endTimeNanos() {
return 0L;
}

@Override
public StatusCode status() {
return StatusCode.UNSET;
}

@Override
public boolean isRecording() {
return false;
}

@Override
public SpanKind kind() {
return SpanKind.INTERNAL;
}

@Override
public String description() {
return null;
}

@Override
public long durationNanos() {
return 0L;
}

@Override
public InstrumentationLibrary library() {
return InstrumentationLibrary.UNKNOWN;
}

@Override
public String appName() {
return null;
}

@Override
public String host() {
return null;
}

@Override
public Span record(Note<?> note) {
return this;
}

@Override
public Scope startTimer(String timerKey) {
return Scope.noop();
}

@Override
public void stopTimer(String timerKey) { }

@Override
public Span attachScope(Scope scope) {
return this;
}

@Override
public SpanInfo info() {
return this;
}

@Override
public SpanId id() {
return SpanId.getInvalid();
}

@Override
public void close() { }
// $COVERAGE-ON$
}
38 changes: 38 additions & 0 deletions money-api/src/main/java/com/comcast/money/api/LinkInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2012 Comcast Cable Communications Management, LLC
*
* Licensed 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 com.comcast.money.api;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;

/**
* A reference to another {@link Span} by span context.
* <p>
* Can be used to associate multiple traces as a part of a batch operation.
*/
public interface LinkInfo {
/**
* @return the context of the linked span
*/
SpanContext spanContext();

/**
* @return the attributes associated with the link between the spans
*/
Attributes attributes();
}
2 changes: 1 addition & 1 deletion money-api/src/main/java/com/comcast/money/api/Note.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @param <T> The type of Note. This is currently limited to Long, String, Boolean and Double
*/
public class Note<T> {
public final class Note<T> {

private final AttributeKey<T> key;
private final T value;
Expand Down
Loading