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

Implement Trace Identifiers. #280

Merged

Conversation

carlosalberto
Copy link
Collaborator

This is done to implement Trace Identifiers, as covered in the RFC:
https://github.com/opentracing/specification/blob/master/rfc/trace_identifiers.md

Probably the most important question is whether we should have traceId() and spanId() instead of tracerIdentifier() and spanIdentifier() respectively - probably the important bit here is that it could (as mentioned in the past) break Tracer implementations

(At this moment, doing this renaming would break MockTracer, as the current methods would have to be renamed to something like longTraceId() and longSpanId(). I'm definitely up for actually breaking it, but I wanted to get some feedback before ;) )

@yurishkuro @tedsuo @CodingFabian @wu-sheng

@CodingFabian
Copy link

I would bikeshed for traceId() and spanId() because thats the signature of the methods we already implemented ;)

@coveralls
Copy link

coveralls commented Jun 12, 2018

Coverage Status

Coverage increased (+0.8%) to 74.874% when pulling ab1f036 on carlosalberto:trace_identifiers_addition into d6c6509 on opentracing:v0.32.0.

@yurishkuro
Copy link
Member

I like the longer name, certainly less intrusive for existing implementations.

cc @pavolloffay @jpkrohling @objectiser

@jpkrohling
Copy link
Contributor

whether we should have traceId() and spanId() instead of tracerIdentifier() and spanIdentifier()

As a consumer of the API, I prefer traceId() instead of tracerIdentifier(), but I wonder why it's not following the standard getTraceId() convention.

I'm definitely up for actually breaking it

+1, especially because we have not reached 1.0 yet.

@objectiser
Copy link
Contributor

I would vote for getTraceId() and getSpanId() - and breaking is fine.

@hypnoce
Copy link
Contributor

hypnoce commented Jun 13, 2018

If we are ok to break things, I would go for traceId() and spanId() as it is the same naming conventions as the current version of the standard : https://w3c.github.io/distributed-tracing/report-trace-context.html#field-value
As for using the get prefix, this is more something esthetic. Both I would suggest choose one option and stick to it throughout the API (my personnal choice here would be without the get prefix).

@objectiser
Copy link
Contributor

@hypnoce get/set is a Java bean convention for properties - and is used in the current Java API, e.g. getBaggageItem, setOperationName, etc.

@hypnoce
Copy link
Contributor

hypnoce commented Jun 13, 2018

@objectiser Indeed it's a specification of Java Beans. They serve a specific purpose. Nevertheless, this convention is not consitently respected in the API

Iterable<Map.Entry<String, String>> baggageItems();

From what I could see throughout the API, I beleive when there is a setter then the Java bean convention is used. If there is only a getter, the method has the same name as the property.

Also, it seems that java is moving out of getters and setters for data objects : http://cr.openjdk.java.net/~briangoetz/amber/datum.html

@carlosalberto
Copy link
Collaborator Author

@wu-sheng @adriancole @felixbarny Something to say on this? ;)

@carlosalberto
Copy link
Collaborator Author

Also pinging @tylerbenson as the author of DataDog's implementation ;)

@tylerbenson
Copy link

Datadog's implementation has the following methods:

long getTraceId()
long getSpanId()

So the return type will conflict either way. Considering the interface already has baggageItems() (as @hypnoce points out), I lean towards not prefixing with get. That is also more consistent with other method names in the API like Scope.span() and Span.context().

@yurishkuro
Copy link
Member

I would also vote to not use get prefix. And using the long form Identifier avoids unpleasant clashes with existing internal APIs.

@tylerbenson
Copy link

I forgot to mention that before... I actually prefer sticking with Id. Long form is kind of grating to me.

@felixbarny
Copy link
Contributor

felixbarny commented Jun 21, 2018

I'm fine with either of the method names, but would prefer traceId() and spanId() to align with TraceContext. FWIW, the Elastic APM OT bridge does not currently offer ways to access the IDs so for us, it would not break anything.

Glad to see this change coming!

@carlosalberto carlosalberto mentioned this pull request Jun 22, 2018
3 tasks
@carlosalberto
Copy link
Collaborator Author

Trying to re-take this discussion: it looks we are slightly more towards traceId() and spanId().

Something to add anybody? Something to add @yurishkuro ? ;) Else, I will update the PR (including MockTracer) in the next days.

@carlosalberto
Copy link
Collaborator Author

Hey all,

Have updated the trace/span identifiers to match the described requirements. Let me know ;)

@hypnoce
Copy link
Contributor

hypnoce commented Jul 26, 2018

Hey @carlosalberto
Thanks for the update.

Trying to re-take this discussion: it looks we are slightly more towards traceId() and spanId().

The to prefix is to avoid breaking the API ?

@tylerbenson
Copy link

@carlosalberto I'm confused... I thought we decided on traceId() and spanId(). Where did we decide to add the to prefix?

@carlosalberto
Copy link
Collaborator Author

@tylerbenson Hey Tyler

Sorry for the PR without a previous explanation - so after discussing it on the Cross-Language call last Friday, based the fear of both breaking tracers and to signal users that retrieving such Ids may incur in object allocation, we decided to go this way.

Of course, this is not set in stone, so we can have a few iterations and pondering on this item ;) Let us know.

@carlosalberto
Copy link
Collaborator Author

@hypnoce Yes, and also to signal potencial allocation when converting the ids in whatever format they have natively to String ;)

@carlosalberto
Copy link
Collaborator Author

After opentracing/specification#125 I'm wondering if we could have this one merged (to the v0.32.0 branch, that is, which is where experimental new features are supposed to land).

@yurishkuro @tylerbenson @objectiser @felixbarny @hypnoce

*
* Globally unique. Every span in a trace shares this ID.
*
* The empty string is a valid return value, while null is not.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to clarify what an empty string represents? i.e. no active trace instance.
Also do we need other text that indicates the return value of toTraceId and toSpanId are either both empty strings (no active trace) or both have ids? For example, I don't think it would be valid to have an empty trace id but a value returned from span id?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's a good point. IMHO it would make sense to mention that the empty string ought to represent missing Trace Identifiers info (and, if this gets approved, make also the note about Span ID & Trace ID working together).

Sounds like a good plan?

cc @yurishkuro @tedsuo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc the original idea was to allow empty string to tracers that are unable to provide a single trace id (e.g. "do not support them", or more likely "this span has many trace IDs").

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend we keep the rules simple, and just say that either method may return an empty string, meaning that the method is not supported for that span.

I doubt implementations will provide one but not the other, but there's no need to make it a rule.

*
* The empty string is a valid return value, while null is not.
*
* @return the trace ID for this context.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please also add something like , or empty if the trace ID does not exist?

@carlosalberto
Copy link
Collaborator Author

Hey all,

Went ahead and clarified in the docs the meaning of an empty String, but without mention of the need of having both of them present or none (to keep things flexible).

Let me know if this is good to merge

cc @objectiser @yurishkuro @pavolloffay @tedsuo

@@ -80,6 +80,5 @@ public Span startManual() {
return NoopSpanImpl.INSTANCE;
}

@Override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, my bad.

public long traceId() { return traceId; }
public long spanId() { return spanId; }


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should remove this line

@carlosalberto
Copy link
Collaborator Author

@pavolloffay @objectiser Small fixes done ;)

@carlosalberto
Copy link
Collaborator Author

Hey all!

Shall we merge this PR?

@hypnoce
Copy link
Contributor

hypnoce commented Sep 17, 2018

Hi all,

I have a small question regarding the format of the strings returned : do they have to obey the w3c format (hex strings) ? Or it's implementation detail ?
Since the w3c is mentioned in the spec, I was wondering.

Thanks

@tedsuo
Copy link
Member

tedsuo commented Sep 26, 2018

@hypnoce there is no restriction. Basically, this should return the “ToString()” equivalent of whatever your tracer’s native ID’s are.

I would like to add w3c specific methods later, but that spec is more complex than just ID’s and it’s not really adopted yet. These accessors are meant to work with any tracing system which supports OT.

@hypnoce
Copy link
Contributor

hypnoce commented Sep 26, 2018

@tedsuo thanks for the update

@carlosalberto
Copy link
Collaborator Author

Hey all,

Unless there's somebody against it, I will be merging this PR in the next days (it has already been approved by a pair of members of the community, and it has received proper tuning ;)

*
* Globally unique. Every span in a trace shares this ID.
*
* An empty String will be returned if there is no method implementation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"no method implementation" reads weird. So is "no trace id present".

Maybe we can simply say "empty string may be returned if the tracer does not support this functionality" and give examples of noop tracer and metrics decorator.

/**
* Return the ID of the trace.
*
* Globally unique. Every span in a trace shares this ID.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Globally unique is incorrect. It is impossible to guarantee (random clashes are acceptable), so we should not state is as a requirement, or we should use SHOULD.

I would only say that it SHOULD be the same for all spans in a single trace.

* Unique within a trace. Each span within a trace contains a different ID.
*
* An empty String will be returned if there is no method implementation
* or there is no span ID present. null is an invalid value return value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comments about wording

/**
* Return the ID of the associated Span.
*
* Unique within a trace. Each span within a trace contains a different ID.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHOULD, not is.

@carlosalberto
Copy link
Collaborator Author

@yurishkuro Done. Thanks again for the latest feedback. Let me know if this is good to go - else, let me know so I can tune docs a little bit more ;)

*
* Observe there is no restriction regarding the format of the returned value, as this
* should simply be the equivalent of calling toString() on the native ID object
* used by the tracer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wording is problematic. It says "should ... ToString" which in many cases is the wrong thing to do, e.g. for int64 IDs. If we want to make a recommendation, it would be that the string format SHOULD match the representation of the IDs in http headers.

The javadoc here should ideally be repeating word for word the specification.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point and good example. So I feel that we should remove this clarification then (if later we add something in the specification itself, we can add it here). Would that make sense to you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, can remove it altogether

@carlosalberto
Copy link
Collaborator Author

@yurishkuro Last edit is done. If this is ok, I will go ahead and merge later today ;)

@yurishkuro
Copy link
Member

🚢

@carlosalberto carlosalberto merged commit 05e90e5 into opentracing:v0.32.0 Oct 14, 2018
@carlosalberto
Copy link
Collaborator Author

Merged :)

@carlosalberto carlosalberto mentioned this pull request Oct 23, 2018
@carlosalberto carlosalberto deleted the trace_identifiers_addition branch March 7, 2019 01:32
carlosalberto added a commit that referenced this pull request Mar 25, 2019
* Deprecate the StringTag.set() overload taking a StringTag. (#262)
* Implement Trace Identifiers. (#280)
* Bump JaCoCo to use a Java 10 friendly version (#306)
* Remove finish span on close (#301)
  * Deprecate finishSpanOnClose on activation.
  * Add ScopeManager.activeSpan() and Tracer.activateSpan().
  * Clarify the API changes and deprecations.
  * Add an error reporting sample to opentracing-testbed.
* Simple layer on top of ByteBuffer for BINARY format. (#276)
* Add generic typed setTag/withTag (#311)
* Allow injecting into maps of type Map<String,Object> (#310)
* Add simple registerIfAbsent to global tracer (#289)
* Split Inject and Extract Builtin interfaces (#316)
* Deprecate ScopeManager.active() (#326)
* Make Tracer extends Closable. (#329)
* Do not make isRegistered() synchronized. (#333)
* Deprecate AutoFinishScopeManager (#335)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet