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

Commit

Permalink
chore(deps): @autotelic/fastify-opentelemetry@0.21.0 (#1376)
Browse files Browse the repository at this point in the history
  • Loading branch information
10xLaCroixDrinker authored Apr 11, 2024
1 parent 484a6b4 commit 2bb1ab2
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 275 deletions.
15 changes: 9 additions & 6 deletions __tests__/integration/one-app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ describe('Tests that require Docker setup', () => {
...defaultFetchOptions,
});
const htmlData = await response.text();
const traceId = response.headers.get('traceid');
const traceId = response.headers.get('x-b3-traceid');
const scriptContents = htmlData.match(
/<script id="initial-state" nonce=\S+>([^<]+)<\/script>/
)[1];
Expand Down Expand Up @@ -1388,15 +1388,15 @@ describe('Tests that require Docker setup', () => {

const formatSpansForSnapshot = (spans, includeAttributes = []) => spans.map(
(span) => `${span.name}: ${JSON.stringify(
span.attributes
span.attributes && span.attributes
.filter((attribute) => (includeAttributes.length === 0
? true
: includeAttributes.includes(attribute.key))
)
.reduce(
(acc, attr) => ({
...acc,
[attr.key]: attr.value.stringValue,
[attr.key]: attr.value.stringValue || attr.value.boolValue,
}),
{}
)
Expand All @@ -1408,7 +1408,7 @@ describe('Tests that require Docker setup', () => {
value: target,
});

expect(response.headers.get('traceid')).toBe(traceId);
expect(response.headers.get('x-b3-traceid')).toBe(traceId);
expect(xB3TraceId).toBe(traceId);
expect(traceparent).toBe(`00-${xB3TraceId}-${xB3TraceSpan}-0${xB3Sampled}`);
const httpSpans = getSpans('@opentelemetry/instrumentation-http', traceId);
Expand Down Expand Up @@ -1447,7 +1447,7 @@ describe('Tests that require Docker setup', () => {
"checkStateForStatusCode: {"req.method":"GET","req.url":"/healthy-frank/ssr-frank"}",
"checkStateForRedirect: {"req.method":"GET","req.url":"/healthy-frank/ssr-frank"}",
"conditionallyAllowCors: {"req.method":"GET","req.url":"/healthy-frank/ssr-frank"}",
"sendHtml: {"req.method":"GET","req.url":"/healthy-frank/ssr-frank"}",
"sendHtml: {"haveStore":true,"haveAppHtml":true,"req.method":"GET","req.url":"/healthy-frank/ssr-frank"}",
"GET /*: {"req.method":"GET","req.url":"/healthy-frank/ssr-frank"}",
]
`);
Expand Down Expand Up @@ -1631,7 +1631,10 @@ describe('Tests that require Docker setup', () => {
pragma: ['no-cache'],
'referrer-policy': ['no-referrer'],
'strict-transport-security': ['max-age=63072000; includeSubDomains'],
traceid: [expect.any(String)],
traceparent: [`00-${response.headers.get('x-b3-traceid')}-${response.headers.get('x-b3-spanid')}-0${response.headers.get('x-b3-sampled')}`],
'x-b3-sampled': [expect.any(String)],
'x-b3-spanid': [expect.any(String)],
'x-b3-traceid': [expect.any(String)],
vary: ['Accept-Encoding'],
'x-content-type-options': ['nosniff'],
'x-dns-prefetch-control': ['off'],
Expand Down
8 changes: 4 additions & 4 deletions __tests__/server/plugins/noopTracer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import Fastify from 'fastify';
import fastifyOpenTelemetry from '@autotelic/fastify-opentelemetry';
import noopTracer from '../../../src/server/plugins/noopTracer';
import tracer from '../../../src/server/plugins/tracer';

describe('noopTracer', () => {
const getTypes = (obj) => Object.entries(obj).reduce((acc, [key, val]) => ({
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('noopTracer', () => {
done();
});
fastify.register((instance, opts, done) => {
instance.register(tracer);
instance.register(fastifyOpenTelemetry, { wrapRoutes: true, propagateToReply: true });
instance.get('/test-actual', async (request, reply) => {
actualApi = { ...request.openTelemetry() };
actualSpan = actualApi.tracer.startSpan('foo', { attributes: { bar: 'baz' } });
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('noopTracer', () => {
});
});

it('should set request.tracingEnabled to false', () => {
expect(requestWithNoopTracer.tracingEnabled).toBe(false);
it('should set request.tracingDisabled to true', () => {
expect(requestWithNoopTracer.tracingDisabled).toBe(true);
});
});
19 changes: 4 additions & 15 deletions __tests__/server/plugins/reactHtml/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ const createTracer = () => {
name,
end: jest.fn(),
recordException: jest.fn(),
addEvent: jest.fn(),
};
spans[name] = span;
return span;
Expand Down Expand Up @@ -525,25 +524,15 @@ describe('reactHtml', () => {
it('adds a tracer span', () => {
sendHtml(request, reply);
expect(tracer.startSpan).toHaveBeenCalledTimes(1);
expect(tracer.startSpan).toHaveBeenCalledWith('sendHtml');
expect(tracer.startSpan).toHaveBeenCalledWith('sendHtml', { attributes: { haveStore: true, haveAppHtml: true } });
expect(tracer.spans.sendHtml.recordException).not.toHaveBeenCalled();
expect(tracer.spans.sendHtml.end).toHaveBeenCalled();
});

it('adds a span event and does not log when tracing is enabled', () => {
request.tracingEnabled = true;
sendHtml(request, reply);
expect(tracer.spans.sendHtml.addEvent).toHaveBeenCalledTimes(1);
expect(tracer.spans.sendHtml.addEvent.mock.calls[0][0]).toMatchInlineSnapshot(
'"\'sendHtml, have store? true, have appHtml? true"'
);
expect(request.log.info).not.toHaveBeenCalled();
});

it('logs and does not add a span event when tracing is disabled', () => {
request.tracingEnabled = false;
it('logs when tracing is disabled', () => {
request.tracingDisabled = true;
sendHtml(request, reply);
expect(tracer.spans.sendHtml.addEvent).not.toHaveBeenCalled();
expect(request.log.info).toHaveBeenCalledTimes(1);
expect(request.log.info.mock.results[0].value).toMatchInlineSnapshot(
'"sendHtml, have store? true, have appHtml? true"'
Expand All @@ -555,7 +544,7 @@ describe('reactHtml', () => {
sendHtml(request, reply);
expect(reply.code).toHaveBeenCalledWith(500);
expect(tracer.startSpan).toHaveBeenCalledTimes(1);
expect(tracer.startSpan).toHaveBeenCalledWith('sendHtml');
expect(tracer.startSpan).toHaveBeenCalledWith('sendHtml', { attributes: { haveStore: true, haveAppHtml: true } });
expect(tracer.spans.sendHtml.recordException).toHaveBeenCalled();
expect(tracer.spans.sendHtml.end).toHaveBeenCalled();
});
Expand Down
126 changes: 0 additions & 126 deletions __tests__/server/plugins/tracer.spec.js

This file was deleted.

Loading

0 comments on commit 2bb1ab2

Please sign in to comment.