-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of Observer APIs (#3)
Initial version of Observer APIs
- Loading branch information
1 parent
539d5d5
commit d3936e9
Showing
3 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
opentracing-observer/src/main/java/io/opentracing/contrib/observer/SpanData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Copyright 2017 The OpenTracing Authors | ||
* | ||
* 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 io.opentracing.contrib.observer; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* This interface provides information about the current {@link io.opentracing.Span} to the observer | ||
* methods. | ||
* | ||
*/ | ||
public interface SpanData { | ||
|
||
/** | ||
* This method returns an id that can be used for correlate actions invoked on a | ||
* stateful observer. It should only be used within the scope of an application, | ||
* to uniquely distinguish one span from another, to enable state to be maintained | ||
* within observer implementation where appropriate. | ||
* | ||
* @return The correlation id for the span, MUST implement equals/hashCode to enable | ||
* it to be used as a map key | ||
*/ | ||
Object getCorrelationId(); | ||
|
||
/** | ||
* The start time of the {@link io.opentracing.Span}. | ||
* | ||
* @return The start time (in microseconds) | ||
*/ | ||
long getStartTime(); | ||
|
||
/** | ||
* The finish time of the {@link io.opentracing.Span}. | ||
* | ||
* @return The finish time (in microseconds), or 0 if not available | ||
*/ | ||
long getFinishTime(); | ||
|
||
/** | ||
* The duration of the {@link io.opentracing.Span}. | ||
* | ||
* @return The duration (in microseconds), or 0 if the span is not finished | ||
*/ | ||
long getDuration(); | ||
|
||
/** | ||
* The operation name of the {@link io.opentracing.Span}. | ||
* | ||
* @return The operation name | ||
*/ | ||
String getOperationName(); | ||
|
||
/** | ||
* This method provides access to the tags associated with the span. If the | ||
* tracer implementation supports multiple values for a key, then only the | ||
* most recent value will be returned. | ||
* | ||
* @return The tags | ||
*/ | ||
Map<String, Object> getTags(); | ||
|
||
/** | ||
* This method returns the tag value, associated with the supplied key, | ||
* if it exists and has a {@link String} type. | ||
* | ||
* @param key The tag key | ||
* @return The value, if exists and is a {@link String} type, otherwise null | ||
*/ | ||
String getStringTag(String key); | ||
|
||
/** | ||
* This method returns the tag value, associated with the supplied key, | ||
* if it exists and has a {@link Number} type. | ||
* | ||
* @param key The tag key | ||
* @return The value, if exists and is a {@link Number} type, otherwise null | ||
*/ | ||
Number getNumberTag(String key); | ||
|
||
/** | ||
* This method returns the tag value, associated with the supplied key, | ||
* if it exists and has a {@link Boolean} type. | ||
* | ||
* @param key The tag key | ||
* @return The value, if exists and is a {@link Boolean} type, otherwise null | ||
*/ | ||
Boolean getBooleanTag(String key); | ||
|
||
/** | ||
* This method retrieves a baggage item associated with the supplied key. | ||
* | ||
* @param key The key | ||
* @return The baggage item, or null if undefined | ||
*/ | ||
Object getBaggageItem(String key); | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
opentracing-observer/src/main/java/io/opentracing/contrib/observer/SpanObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Copyright 2017 The OpenTracing Authors | ||
* | ||
* 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 io.opentracing.contrib.observer; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* This interface represents an observer used to receive notifications related to a {@link io.opentracing.Span}. | ||
* <p> | ||
* Note: All of these callback functions are called after the associated operation has been performed on the | ||
* {@link io.opentracing.Span}, i.e. they are post-change notifications. | ||
*/ | ||
public interface SpanObserver { | ||
|
||
/** | ||
* Notifies the observer that the operation name has been changed. | ||
* | ||
* @param spanData The data for the span | ||
* @param operationName The new operation name | ||
*/ | ||
void onSetOperationName(SpanData spanData, String operationName); | ||
|
||
/** | ||
* Notifies the observer that the tag with the supplied key has been set or updated | ||
* on a {@link io.opentracing.Span}. | ||
* | ||
* @param spanData The data for the span | ||
* @param key The tag key | ||
* @param value The tag value | ||
*/ | ||
void onSetTag(SpanData spanData, String key, Object value); | ||
|
||
/** | ||
* Notifies the observer that the named baggage item has been set/changed. | ||
* | ||
* @param spanData The data for the span | ||
* @param key The baggage key | ||
* @param value The baggage value | ||
*/ | ||
void onSetBaggageItem(SpanData spanData, String key, String value); | ||
|
||
/** | ||
* Notifies the observer that a log event has been recorded. | ||
* | ||
* @param spanData The data for the span | ||
* @param timestampMicroseconds The explicit timestamp for the log record. Must be greater than or equal to the | ||
* Span's start timestamp. | ||
* @param fields key:value log fields. Tracer implementations should support String, numeric, and boolean values; | ||
* some may also support arbitrary Objects. | ||
*/ | ||
void onLog(SpanData spanData, long timestampMicroseconds, Map<String, ?> fields); | ||
|
||
/** | ||
* Notifies the observer that a log event has been recorded. | ||
* | ||
* @param spanData The data for the span | ||
* @param timestampMicroseconds The explicit timestamp for the log record. Must be greater than or equal to the | ||
* Span's start timestamp. | ||
* @param event the event value; often a stable identifier for a moment in the Span lifecycle | ||
*/ | ||
void onLog(SpanData spanData, long timestampMicroseconds, String event); | ||
|
||
/** | ||
* Notifies the observer that a span associated with the supplied data has finished. | ||
* | ||
* @param spanData The data for the span | ||
* @param finishMicros The finish time in microseconds | ||
*/ | ||
void onFinish(SpanData spanData, long finishMicros); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters