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

Error: Must be valid TraceId instance #422

Closed
russell-matt opened this issue Jul 24, 2019 · 20 comments · Fixed by #423
Closed

Error: Must be valid TraceId instance #422

russell-matt opened this issue Jul 24, 2019 · 20 comments · Fixed by #423
Assignees

Comments

@russell-matt
Copy link
Contributor

After upgrading to version 0.18.5 of zipkin-instrumentation-restify and zipkin, I am getting the following error when the request to my server comes in with a traceId: "Error: Must be valid TraceId instance".

I've narrowed the problem down to the following snippet of code in zipkin/tracer/index.js inside the join function

if (!(traceId instanceof TraceId)) {
    throw new Error('Must be valid TraceId instance');
}

This if is always resulting to false, after inspecting the traceid passed to this function, I found the following.

traceId parameter:

TraceId {
  _traceId: 'b7daf2ae1b9e2555',
  _parentId:
   { type: [Getter],
     present: [Getter],
     map: [Function: map],
     ifPresent: [Function: ifPresent],
     flatMap: [Function: flatMap],
     getOrElse: [Function: getOrElse],
     equals: [Function: equals],
     toString: [Function: toString] },
  _spanId: 'b7daf2ae1b9e2555',
  _sampled:
   { type: [Getter],
     present: [Getter],
     map: [Function: map],
     ifPresent: [Function: ifPresent],
     flatMap: [Function: flatMap],
     getOrElse: [Function: getOrElse],
     equals: [Function: equals],
     toString: [Function: toString] },
  _debug: false,
  _shared: false }

traceId instanceof TraceId_1: false
traceId.constructor.name: TraceId
TraceId_1.constructor.name: Function
TraceId.constructor.name: Function

Please note: The usage of TraceId_1 is because that is the output produced after transpilation, and hence is what is being checked in the code when it is actually running.

if (!(traceId instanceof TraceId_1)) {
    throw new Error('Must be valid TraceId instance');
}

This issue only happens if the request is made with the traceid and spanid headers populated.

@ReeceGarratt
Copy link

I've got a similar issue. Looks like its the same cause.

Please look into this.

@Cyberclown
Copy link

Same, disaster

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Jul 24, 2019 via email

@codefromthecrypt codefromthecrypt self-assigned this Jul 24, 2019
@Cyberclown
Copy link

Normal js, es5 if im not mistaken

@russell-matt
Copy link
Contributor Author

@adriancole No, I'm using plain javascript running on Node version 10.11.0 locally, and alpine-8 on server.

@codefromthecrypt
Copy link
Member

#328 introduced this, specifically f665dc3

looking into it and will put a patch up ASAP

@codefromthecrypt
Copy link
Member

as I understand it, this is a trace Id but not the exact type, hence always fail. So we need to use duck typing or loosen up, right?

@cbspindler
Copy link

Getting similar issue, will keep watching thread

@russell-matt
Copy link
Contributor Author

as I understand it, this is a trace Id but not the exact type, hence always fail. So we need to use duck typing or loosen up, right?

I'm not entirely sure if duck typing would help. From what I could see the type was what we wanted it to be, but the instanceof check fails. It seemed to be caused because babel transpiles the class down to a function, and instanceof fails because of this.

Loosing up the check should solve it, as long as we're not doing a hard typing check. Thanks for the quick reply and action, will look forward to the patch.

@codefromthecrypt
Copy link
Member

_traceId and _spanId are required.. what if we temporarily use this as a type check until a better way is found? ps anyway if you have a better way, please let me know :)

@russell-matt
Copy link
Contributor Author

_traceId and _spanId are required.. what if we temporarily use this as a type check until a better way is found? ps anyway if you have a better way, please let me know :)

Sounds like it would work. Essentially all we need to do is make sure that what we want to do in the function will not result in a type error, so checking whatever properties we require to do that should be sufficient.

On that note, the error that was being thrown was bubbling all the way up to the top, and being thrown out of the middleware, thus causing the restify server to crash. Is this intended? It seems odd for a middleware to not catch this error and handle gracefully.

@codefromthecrypt
Copy link
Member

different topic but yeah, crashing requests is bad.

@codefromthecrypt
Copy link
Member

can someone take a look? I can cut a release immediately after #423

@codefromthecrypt
Copy link
Member

ps sorry about the TraceIdApocalypse

@codefromthecrypt
Copy link
Member

@russell-matt
Copy link
Contributor Author

Change looks like it should resolve our issue. Will test it and let you know.

@russell-matt
Copy link
Contributor Author

Updated to 0.18.6, tested and everything looks fine. Thanks @adriancole for the fast resolution!

@jcchavezs
Copy link
Contributor

On that note, the error that was being thrown was bubbling all the way up to the top, and being thrown out of the middleware, thus causing the restify server to crash. Is this intended? It seems odd for a middleware to not catch this error and handle gracefully.

@russell-matt do you mind opening an issue for this?

@russell-matt
Copy link
Contributor Author

@jcchavezs Done, #424

@jcchavezs
Copy link
Contributor

Thank you @russell-matt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants