Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

* fix(otlp-grpc-exporter-base): avoid TypeError on exporter shutdown [#4612](https://github.com/open-telemetry/opentelemetry-js/pull/4612)

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class GrpcExporterTransport implements IExporterTransport {
constructor(private _parameters: GrpcExporterTransportParameters) {}

shutdown() {
this._client?.shutdown();
this._client?.close();
}

send(data: Uint8Array): Promise<ExportResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,37 +136,49 @@ describe('GrpcExporterTransport', function () {
});
});
describe('shutdown', function () {
let shutdownHandle: () => void | undefined;
const serverTestContext: ServerTestContext = {
requests: [],
serverResponseProvider: () => {
return { error: null, buffer: Buffer.from([]) };
},
};

beforeEach(async function () {
shutdownHandle = await startServer(serverTestContext);
});

afterEach(function () {
shutdownHandle();

// clear context
serverTestContext.requests = [];
serverTestContext.serverResponseProvider = () => {
return { error: null, buffer: Buffer.from([]) };
};

sinon.restore();
});

it('before send() does not error', function () {
const transport = new GrpcExporterTransport(simpleClientConfig);
transport.shutdown();

// no assertions, just checking that it does not throw any errors.
});

it('calls client shutdown if client is defined', function () {
// arrange
const transport = new GrpcExporterTransport({
metadata: createEmptyMetadata,
timeoutMillis: 100,
grpcPath: 'path',
grpcName: 'name',
credentials: createInsecureCredentials,
compression: 'gzip',
address: 'localhost:1234',
});
const shutdownStub = sinon.stub();
transport['_client'] = {
shutdown: shutdownStub,
};
it('calls _client.close() if client is defined', async function () {
const transport = new GrpcExporterTransport(simpleClientConfig);
// send something so that client is defined
await transport.send(Buffer.from([1, 2, 3]));
assert.ok(transport['_client'], '_client is not defined after send()');
const closeSpy = sinon.spy(transport['_client'], 'close');

// act
transport.shutdown();

// assert
sinon.assert.calledOnce(shutdownStub);
sinon.assert.calledOnce(closeSpy);
});
});
describe('send', function () {
Expand Down