Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #50 from felixbarny/set-operation-name
Browse files Browse the repository at this point in the history
Add Span#setOperationName
  • Loading branch information
michaelsembwever authored Sep 10, 2016
2 parents f14014b + 020c30d commit 0b95031
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
7 changes: 7 additions & 0 deletions opentracing-api/src/main/java/io/opentracing/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,11 @@ public interface Span extends AutoCloseable {
* @return the value of the baggage item identified by the given key, or null if no such item could be found
*/
String getBaggageItem(String key);

/**
* Sets the string name for the logical operation this span represents.
*
* @return this Span instance, for chaining
*/
Span setOperationName(String operationName);
}
2 changes: 2 additions & 0 deletions opentracing-api/src/main/java/io/opentracing/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface Tracer {
/**
* Return a new SpanBuilder for a Span with the given `operationName`.
*
* <p>You can override the operationName later via {@link Span#setOperationName(String)}.
*
* <p>A contrived example:
* <pre>{@code
Tracer tracer = ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

abstract class AbstractSpan implements Span, SpanContext {

final String operationName;
String operationName;

protected final Map<String,String> baggage = new HashMap<>();

Expand Down Expand Up @@ -114,15 +114,21 @@ public final Span log(long instantMicroseconds, String message, /* @Nullable */
return this;
}

@Override
public Span setOperationName(String operationName) {
this.operationName = operationName;
return this;
}

final class LogData {
private final Instant time;
private final String message;
private final Object payload;

LogData(Instant time, String message, Object payload) {
this.time = time;
this.message = message;
this.payload = payload;
}
private final Instant time;
private final String message;
private final Object payload;

LogData(Instant time, String message, Object payload) {
this.time = time;
this.message = message;
this.payload = payload;
}
}
}
5 changes: 5 additions & 0 deletions opentracing-impl/src/main/java/io/opentracing/NoopSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ public Span log(long timestampMicroseconds, String eventName, Object payload) {
@Override
public String getBaggageItem(String key) { return null; }

@Override
public Span setOperationName(String operationName) {
return this;
}

}
15 changes: 11 additions & 4 deletions opentracing-mock/src/main/java/io/opentracing/mock/MockSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
*/
package io.opentracing.mock;

import io.opentracing.Span;
import io.opentracing.SpanContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

import io.opentracing.Span;
import io.opentracing.SpanContext;

/**
* MockSpans are created via MockTracer.buildSpan(...), but they are also returned via calls to
* MockTracer.finishedSpans(). They provide accessors to all Span state.
Expand All @@ -39,11 +39,18 @@ public final class MockSpan implements Span {
private long finishMicros;
private final Map<String, Object> tags;
private final List<LogEntry> logEntries = new ArrayList<>();
private final String operationName;
private String operationName;

public String operationName() {
return this.operationName;
}

@Override
public Span setOperationName(String operationName) {
this.operationName = operationName;
return this;
}

/**
* TODO: Support multiple parents in this API.
*
Expand Down

0 comments on commit 0b95031

Please sign in to comment.