From 8195783341db8ac77550b586498e3373e4f7d1ac Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 4 Jul 2017 10:13:22 +0800 Subject: [PATCH] Adds tests that shows how to override the span name (#97) Default span names are good choices as they are bounded. However, users may want to change these to other bounded choices (ex names that don't include variables). This shows how to accomplish this. Note: it is quite common for custom code to get naming wrong, by using high cardinality names such as specific http paths. This is one reason why defaults are limited, as tags/binary annotations can be used to add more specific lookup criteria without degrading the UI. See #96 See https://github.com/openzipkin/openzipkin.github.io/issues/70#issuecomment-290880552 --- packages/zipkin/test/batch-recorder.test.js | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/zipkin/test/batch-recorder.test.js b/packages/zipkin/test/batch-recorder.test.js index 51b7b44a..bfeeb08f 100644 --- a/packages/zipkin/test/batch-recorder.test.js +++ b/packages/zipkin/test/batch-recorder.test.js @@ -55,6 +55,38 @@ describe('Batch Recorder', () => { }); }); + // Applications can override the span name via trace.recordRpc + it('should record span name as last recordRpc', () => { + const logSpan = sinon.spy(); + + const ctxImpl = new ExplicitContext(); + const logger = {logSpan}; + const recorder = new BatchRecorder({logger}); + const trace = new Tracer({ctxImpl, recorder}); + + ctxImpl.scoped(() => { + trace.setId(new TraceId({ + traceId: None, + parentId: new Some('a'), + spanId: 'c', + sampled: new Some(true) + })); + + trace.recordServiceName('SmoothieStore'); + trace.recordRpc('buySmoothie'); + trace.recordAnnotation(new Annotation.ServerRecv()); + + // some customization code scoped to this trace ID resets the span name + trace.recordRpc('rentSmoothie'); + + trace.recordAnnotation(new Annotation.ServerSend()); + + const loggedSpan = logSpan.getCall(0).args[0]; + + expect(loggedSpan.name).to.eql(new Some('rentSmoothie')); + }); + }); + it('should set MutableSpan.startTimestamp to first record', () => { const clock = lolex.install(12345678); const logSpan = sinon.spy();