Skip to content

Commit c3d68bf

Browse files
refactor: remove factory function
It can just be done explicitly by anything that needs it Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 217e2a0 commit c3d68bf

File tree

3 files changed

+1
-49
lines changed

3 files changed

+1
-49
lines changed

docs/telemetry.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ thisThrows()
229229

230230
### Important Notes
231231

232-
- 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.
233-
234232
- If a nested function does not use a `run()` then it will not be part of the call stack.
235233

236234
```typescript

packages/core/src/shared/telemetry/util.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,3 @@ export function withTelemetryContext(opts: TelemetryContextArgs) {
452452
})
453453
}
454454
}
455-
456-
/**
457-
* Returns a custom {@link withTelemetryContext} decorator, but with some values predefined
458-
* to deduplicate boilerplate for a class that will use this decorator multiple times.
459-
*/
460-
export function withTelemetryContextFactory(predefinedOpts: Omit<TelemetryContextArgs, 'name'>) {
461-
return (opts: TelemetryContextArgs) => withTelemetryContext({ ...predefinedOpts, ...opts })
462-
}

packages/core/src/test/shared/telemetry/spans.test.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { assertTelemetry, getMetrics, installFakeClock } from '../../testUtil'
1111
import { selectFrom } from '../../../shared/utilities/tsUtils'
1212
import { getAwsServiceError } from '../errors.test'
1313
import { sleep } from '../../../shared'
14-
import { withTelemetryContext, withTelemetryContextFactory } from '../../../shared/telemetry/util'
14+
import { withTelemetryContext } from '../../../shared/telemetry/util'
1515
import { SinonSandbox } from 'sinon'
1616
import sinon from 'sinon'
1717
import * as crypto from '../../../shared/crypto'
@@ -682,44 +682,6 @@ describe('TelemetryTracer', function () {
682682
(e) => e === arbitraryError
683683
)
684684
})
685-
686-
const customWithTelemetryContext = withTelemetryContextFactory({ class: 'TestCustomContext', emit: true })
687-
688-
class TestCustomContext {
689-
@customWithTelemetryContext({ name: 'testMethod' })
690-
testMethod() {
691-
return
692-
}
693-
694-
@customWithTelemetryContext({ name: 'overridesTheClass', class: 'Overidden' })
695-
overridesTheClass() {
696-
return
697-
}
698-
}
699-
700-
it('Uses predefined context', function () {
701-
const inst = new TestCustomContext()
702-
inst.testMethod()
703-
assertTelemetry('function_call', [
704-
{
705-
functionName: 'testMethod',
706-
className: 'TestCustomContext',
707-
source: 'TestCustomContext#testMethod',
708-
},
709-
])
710-
})
711-
712-
it('can override the predefined context', function () {
713-
const inst = new TestCustomContext()
714-
inst.overridesTheClass()
715-
assertTelemetry('function_call', [
716-
{
717-
functionName: 'overridesTheClass',
718-
className: 'Overidden',
719-
source: 'Overidden#overridesTheClass',
720-
},
721-
])
722-
})
723685
})
724686

725687
describe('withTraceId()', function () {

0 commit comments

Comments
 (0)