[Tags.HTTP_URL]: url, fallback: isFallback, public: isPublic,
assert.deepEqual(tags[1], { 'span.kind': 'client', [Tags.HTTP_URL]: 'https://fragment/1', id: 'test', fallback: false,
it('should start and finish span with https', async () => { // WARNING: nock doesn't work well with https instrumentation // create real request await request('https://risingstack.com') expect(cls.startChildSpan).to.be.calledWith(tracer, instrumentation.OPERATION_NAME, { tags: { [Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT, [Tags.HTTP_URL]: 'https://risingstack.com:443/', [Tags.HTTP_METHOD]: 'GET' } }) expect(mockChildSpan.setTag).to.have.calledWith(Tags.HTTP_STATUS_CODE, 200) expect(mockChildSpan.finish).to.have.callCount(1) })
it('should start and finish span with http', async () => { nock('http://risingstack.com') .get('/foo') .reply(200) await request({ uri: 'http://risingstack.com/foo', query: { token: 'secret' } }) expect(cls.startChildSpan).to.be.calledWith(tracer, instrumentation.OPERATION_NAME, { tags: { [Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT, [Tags.HTTP_URL]: 'http://risingstack.com:80/foo', [Tags.HTTP_METHOD]: 'GET' } }) expect(mockChildSpan.setTag).to.have.calledWith(Tags.HTTP_STATUS_CODE, 200) expect(mockChildSpan.finish).to.have.callCount(1) })
/** * Called by Tracer when a span is finished * @method reportFinish * @param {Span} span */ reportFinish (span) { assert(span instanceof Span, 'span is required') // Ignore by tag value const isIgnored = Object.entries(this._options.ignoreTags).some(([tagKey, regexp]) => { const tagValue = span.getTag(tagKey) return tagValue && tagValue.match(regexp) }) if (isIgnored) { return } // Operation metrics this._reportOperationFinish(span) // HTTP Request if (span.getTag(Tags.SPAN_KIND) === Tags.SPAN_KIND_RPC_SERVER && (span.getTag(Tags.HTTP_URL) || span.getTag(Tags.HTTP_METHOD) || span.getTag(Tags.HTTP_STATUS_CODE))) { this._reportHttpRequestFinish(span) } }
requestSpan.setTag(Tags.HTTP_URL, req.url) requestSpan.setTag(Tags.HTTP_METHOD, req.method || 'GET') requestSpan.setTag(Tags.HTTP_STATUS_CODE, 200)
it('should skip operation metrics by tag value', function () { // init const prometheusReporter = new PrometheusReporter({ ignoreTags: { [Tags.HTTP_URL]: /foo/ } }) const metricsOperationDurationSeconds = prometheusReporter._metricsOperationDurationSeconds() const metricsStub = { observe: this.sandbox.spy() } this.sandbox.stub(metricsOperationDurationSeconds, 'labels').callsFake(() => metricsStub) // generate data const tracer = new Tracer('service') const span = tracer.startSpan('my-operation') span.setTag(Tags.HTTP_URL, 'http://127.0.0.1/foo') clock.tick(100) span.finish() prometheusReporter.reportFinish(span) // assert expect(metricsOperationDurationSeconds.labels).to.have.callCount(0) expect(metricsStub.observe).to.have.callCount(0) })
const reporter = new PrometheusReporter({ ignoreTags: { [Tags.HTTP_URL]: /bar/ span1.setTag(Tags.HTTP_URL, 'http://127.0.0.1/foo') span1.setTag(Tags.HTTP_METHOD, 'GET') span1.setTag(Tags.HTTP_STATUS_CODE, 200) span2.setTag(Tags.HTTP_URL, 'http://127.0.0.1/bar') span2.setTag(Tags.HTTP_METHOD, 'GET') span2.setTag(Tags.HTTP_STATUS_CODE, 200)