Skip to content

Commit

Permalink
refactor: remove factory function
Browse files Browse the repository at this point in the history
It can just be done explicitly by anything that needs it

Signed-off-by: nkomonen-amazon <[email protected]>
  • Loading branch information
nkomonen-amazon committed Nov 15, 2024
1 parent 217e2a0 commit c3d68bf
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 49 deletions.
2 changes: 0 additions & 2 deletions docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ thisThrows()

### Important Notes

- You can avoid redundancy when repeating fields like `class` in `@withTelemetryContext` by using `withTelemetryContextFactory()`. It builds a new decorator with pre-defined values that you choose.

- If a nested function does not use a `run()` then it will not be part of the call stack.

```typescript
Expand Down
8 changes: 0 additions & 8 deletions packages/core/src/shared/telemetry/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,3 @@ export function withTelemetryContext(opts: TelemetryContextArgs) {
})
}
}

/**
* Returns a custom {@link withTelemetryContext} decorator, but with some values predefined
* to deduplicate boilerplate for a class that will use this decorator multiple times.
*/
export function withTelemetryContextFactory(predefinedOpts: Omit<TelemetryContextArgs, 'name'>) {
return (opts: TelemetryContextArgs) => withTelemetryContext({ ...predefinedOpts, ...opts })
}
40 changes: 1 addition & 39 deletions packages/core/src/test/shared/telemetry/spans.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { assertTelemetry, getMetrics, installFakeClock } from '../../testUtil'
import { selectFrom } from '../../../shared/utilities/tsUtils'
import { getAwsServiceError } from '../errors.test'
import { sleep } from '../../../shared'
import { withTelemetryContext, withTelemetryContextFactory } from '../../../shared/telemetry/util'
import { withTelemetryContext } from '../../../shared/telemetry/util'
import { SinonSandbox } from 'sinon'
import sinon from 'sinon'
import * as crypto from '../../../shared/crypto'
Expand Down Expand Up @@ -682,44 +682,6 @@ describe('TelemetryTracer', function () {
(e) => e === arbitraryError
)
})

const customWithTelemetryContext = withTelemetryContextFactory({ class: 'TestCustomContext', emit: true })

class TestCustomContext {
@customWithTelemetryContext({ name: 'testMethod' })
testMethod() {
return
}

@customWithTelemetryContext({ name: 'overridesTheClass', class: 'Overidden' })
overridesTheClass() {
return
}
}

it('Uses predefined context', function () {
const inst = new TestCustomContext()
inst.testMethod()
assertTelemetry('function_call', [
{
functionName: 'testMethod',
className: 'TestCustomContext',
source: 'TestCustomContext#testMethod',
},
])
})

it('can override the predefined context', function () {
const inst = new TestCustomContext()
inst.overridesTheClass()
assertTelemetry('function_call', [
{
functionName: 'overridesTheClass',
className: 'Overidden',
source: 'Overidden#overridesTheClass',
},
])
})
})

describe('withTraceId()', function () {
Expand Down

0 comments on commit c3d68bf

Please sign in to comment.