Skip to content

Commit

Permalink
feat: Use trace types from interfaces (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
LautaroPetaccio authored Feb 27, 2023
1 parent 8175aec commit 52fc3e2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 70 deletions.
76 changes: 17 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"node": ">=16"
},
"dependencies": {
"@well-known-components/interfaces": "^1.2.0",
"tslib": "^2.5.0"
},
"files": [
Expand All @@ -35,8 +36,6 @@
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"@well-known-components/http-server": "^1.1.6",
"@well-known-components/interfaces": "^1.1.3",
"@well-known-components/tracer-component": "^1.0.0",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
Expand Down
3 changes: 1 addition & 2 deletions src/component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { IHttpServerComponent } from '@well-known-components/interfaces'
import type { ITracerComponent, TraceContext } from '@well-known-components/tracer-component'
import type { IHttpServerComponent, ITracerComponent, TraceContext } from '@well-known-components/interfaces'
import { parseTraceParentHeader, parseTraceState } from './logic'
import { IHttpTracerComponent } from './types'

Expand Down
6 changes: 3 additions & 3 deletions src/logic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Trace } from '@well-known-components/tracer-component'
import type { Trace } from '@well-known-components/interfaces'

/**
* Parses the tracestate header into an object.
Expand Down Expand Up @@ -44,9 +44,9 @@ export function parseTraceParentHeader(traceParent: string): Trace | null {
parentIdIsInvalid
? null
: {
version: traceParentProperties[0],
version: parseInt(traceParentProperties[0], 16),
traceId: traceParentProperties[1],
parentId: traceParentProperties[2],
traceFlags: traceParentProperties[3]
traceFlags: parseInt(traceParentProperties[3], 16)
}
}
4 changes: 2 additions & 2 deletions test/component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ITracerComponent } from '@well-known-components/tracer-component'
import type { IHttpServerComponent } from '@well-known-components/interfaces'
import type { ITracerComponent, IHttpServerComponent } from '@well-known-components/interfaces'
import { createHttpTracerComponent } from '../src'
import { parseTraceParentHeader } from '../src/logic'

Expand All @@ -20,6 +19,7 @@ beforeEach(() => {
mockedGetTraceStateString = jest.fn()
tracerComponentMock = {
span: jest.fn().mockImplementation((_name, spanFunction) => spanFunction()),
isInsideOfTraceSpan: jest.fn(),
getSpanId: jest.fn(),
getTrace: jest.fn(),
getTraceString: mockedGetTraceString,
Expand Down
4 changes: 2 additions & 2 deletions test/logic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ describe('when parsing the trace parent header', () => {
describe('and the header is well formatted', () => {
it('should return a trace object', () => {
expect(parseTraceParentHeader('00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01')).toEqual({
version: '00',
version: 0,
traceId: '4bf92f3577b34da6a3ce929d0e0e4736',
parentId: '00f067aa0ba902b7',
traceFlags: '01'
traceFlags: 1
})
})
})
Expand Down

0 comments on commit 52fc3e2

Please sign in to comment.