-
Notifications
You must be signed in to change notification settings - Fork 4
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
Initial version of Observer APIs #3
Changes from 1 commit
3b3d363
63cfe5b
a233823
e94ac6e
65d1401
79dea5c
9be2556
5c10701
92b2224
f0faa91
5d38bba
d70fad0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* 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 io.opentracing.Span; | ||
import io.opentracing.SpanContext; | ||
|
||
/** | ||
* This interface represents an observer used to receive notifications related to a {@link SpanBuilder}. | ||
* | ||
*/ | ||
public interface SpanBuilderObserver { | ||
|
||
/** | ||
* Notifies observer that the named tag has been set/changed. | ||
* | ||
* @param name The tag name | ||
* @param value The tag value | ||
*/ | ||
void onWithTag(String name, Object value); | ||
|
||
/** | ||
* Notifies observer that a reference has been added of the specified | ||
* type. | ||
* | ||
* @param referenceType The reference type | ||
* @param referencedContext The referenced span context | ||
*/ | ||
void onAddReference(String referenceType, SpanContext referencedContext); | ||
|
||
/** | ||
* Notifies the observer that the {@link Span} has been started. | ||
* | ||
* @param span The started span | ||
* @param startMicros The start time in microseconds | ||
* @return The observer for the span | ||
*/ | ||
SpanObserver onStart(Span span, long startMicros); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* 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 Span}. | ||
* | ||
*/ | ||
public interface SpanObserver { | ||
|
||
/** | ||
* Notifies the observer that the operation name has been changed. | ||
* | ||
* @param operationName The new operation name | ||
*/ | ||
void onSetOperationName(String operationName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: the operation name can be set multiple times for a span and could also be set via the SpanBuilder. As you only know the operation name for certain when |
||
|
||
/** | ||
* Notifies the observer that the named tag has been set/changed. | ||
* | ||
* @param name The tag name | ||
* @param value The tag value | ||
*/ | ||
void onSetTag(String name, Object value); | ||
|
||
/** | ||
* Notifies the observer that the named baggage item has been set/changed. | ||
* | ||
* @param key The baggage key | ||
* @param value The baggage value | ||
*/ | ||
void onSetBaggageItem(String key, String value); | ||
|
||
/** | ||
* Notifies the observer that a log event has been recorded. | ||
* | ||
* @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(long timestampMicroseconds, Map<String, ?> fields); | ||
|
||
/** | ||
* Notifies the observer that a log event has been recorded. | ||
* | ||
* @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(long timestampMicroseconds, String event); | ||
|
||
/** | ||
* Notifies the observer that the associated {@link Span} has finished. | ||
* | ||
* @param finishMicros The finish time in microseconds | ||
*/ | ||
void onFinish(long finishMicros); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of the other methods (apart from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use the instance to set additional tags onFinish. Another use case is reporting. See also https://github.com/opentracing-contrib/java-span-reporter/blob/master/span-reporter/src/main/java/io/opentracing/contrib/reporter/Reporter.java#L22 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In both these cases the Observer instance could save the span supplied with the Currently the go observer only supplies it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's the key point. In stagemonitor, I have the notion of a StatelessEventListener which is a single instance reused for all spans. This saves a lot of object instantiation and reduces GC overhead imposed by the agent. Another feature my impl currently supports is altering and omitting of certain tags via the onSetTag method. |
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe join with
SpanObserver
? How would implementations know wether a specific tag is set on theSpanBuilder
or theSpan
? If there is only oneonSetTag
method which is invoked no matter if the tag was actually set on aSpanBuilder
or aSpan
, people don't have to worry about that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean have one interface
SpanObserver
that is used by theSpanBuilder
to notify, so it would potentially callonSetTag
andonAddReference
beforeonStart
, and then afterwards potentially haveonSetTag
called other times before finallyonFinish
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. That's how I implemented this for stagemonitor: https://github.com/stagemonitor/stagemonitor/blob/master/stagemonitor-tracing/src/main/java/org/stagemonitor/tracing/wrapper/SpanEventListener.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be fine my me - although would like to get other feedback first before applying change.