-
Notifications
You must be signed in to change notification settings - Fork 828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: new interface for ExportResult #1569 #1643
Changes from 8 commits
a7199e3
b2d4d10
2b45bc7
67831bd
a3cca78
acbf14a
06f3b7a
be5e4cf
6af9a7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,7 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import { | ||
NoopLogger, | ||
setGlobalErrorHandler, | ||
loggingErrorHandler, | ||
} from '@opentelemetry/core'; | ||
import { ExportResultCode, NoopLogger } from '@opentelemetry/core'; | ||
import * as assert from 'assert'; | ||
import * as sinon from 'sinon'; | ||
import { CollectorMetricExporter } from '../../src/platform/browser/index'; | ||
|
@@ -166,25 +162,12 @@ describe('CollectorMetricExporter - web', () => { | |
}); | ||
|
||
it('should log the error message', done => { | ||
const spyLoggerError = sinon.spy(); | ||
const handler = loggingErrorHandler({ | ||
debug: sinon.fake(), | ||
info: sinon.fake(), | ||
warn: sinon.fake(), | ||
error: spyLoggerError, | ||
}); | ||
setGlobalErrorHandler(handler); | ||
const spyLoggerDebug = sinon.stub(collectorExporter.logger, 'debug'); | ||
spyBeacon.restore(); | ||
spyBeacon = sinon.stub(window.navigator, 'sendBeacon').returns(false); | ||
|
||
collectorExporter.export(metrics, () => {}); | ||
|
||
setTimeout(() => { | ||
const response: any = spyLoggerError.args[0][0] as string; | ||
assert.ok(response.includes('sendBeacon - cannot send')); | ||
assert.strictEqual(spyLoggerDebug.args.length, 1); | ||
|
||
collectorExporter.export(metrics, result => { | ||
assert.deepStrictEqual(result.code, ExportResultCode.FAILED); | ||
assert.ok(result.error?.message.includes('cannot send')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the message is still There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i just rewrote the code without thinking about what was in place, i will add it back |
||
done(); | ||
}); | ||
}); | ||
|
@@ -290,19 +273,9 @@ describe('CollectorMetricExporter - web', () => { | |
}); | ||
|
||
it('should log the error message', done => { | ||
const spyLoggerError = sinon.spy(); | ||
const handler = loggingErrorHandler({ | ||
debug: sinon.fake(), | ||
info: sinon.fake(), | ||
warn: sinon.fake(), | ||
error: spyLoggerError, | ||
}); | ||
setGlobalErrorHandler(handler); | ||
|
||
collectorExporter.export(metrics, () => { | ||
const response = spyLoggerError.args[0][0] as string; | ||
assert.ok(response.includes('"code":"400"')); | ||
|
||
collectorExporter.export(metrics, result => { | ||
assert.deepStrictEqual(result.code, ExportResultCode.FAILED); | ||
assert.ok(result.error?.message.includes('Failed to export')); | ||
assert.strictEqual(spyBeacon.callCount, 0); | ||
done(); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,7 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import { | ||
NoopLogger, | ||
setGlobalErrorHandler, | ||
loggingErrorHandler, | ||
} from '@opentelemetry/core'; | ||
import { NoopLogger, ExportResultCode } from '@opentelemetry/core'; | ||
import { ReadableSpan } from '@opentelemetry/tracing'; | ||
import * as assert from 'assert'; | ||
import * as sinon from 'sinon'; | ||
|
@@ -135,29 +131,12 @@ describe('CollectorTraceExporter - web', () => { | |
}); | ||
|
||
it('should log the error message', done => { | ||
const spyLoggerError = sinon.spy(); | ||
const handler = loggingErrorHandler({ | ||
debug: sinon.fake(), | ||
info: sinon.fake(), | ||
warn: sinon.fake(), | ||
error: spyLoggerError, | ||
}); | ||
setGlobalErrorHandler(handler); | ||
|
||
const spyLoggerDebug = sinon.stub( | ||
collectorTraceExporter.logger, | ||
'debug' | ||
); | ||
spyBeacon.restore(); | ||
spyBeacon = sinon.stub(window.navigator, 'sendBeacon').returns(false); | ||
|
||
collectorTraceExporter.export(spans, () => {}); | ||
|
||
setTimeout(() => { | ||
const response = spyLoggerError.args[0][0] as string; | ||
assert.ok(response.includes('sendBeacon - cannot send')); | ||
assert.strictEqual(spyLoggerDebug.args.length, 1); | ||
|
||
collectorTraceExporter.export(spans, result => { | ||
assert.deepStrictEqual(result.code, ExportResultCode.FAILED); | ||
assert.ok(result.error?.message.includes('cannot send')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here the same |
||
done(); | ||
}); | ||
}); | ||
|
@@ -236,21 +215,9 @@ describe('CollectorTraceExporter - web', () => { | |
}); | ||
|
||
it('should log the error message', done => { | ||
const spyLoggerError = sinon.spy(); | ||
const handler = loggingErrorHandler({ | ||
debug: sinon.fake(), | ||
info: sinon.fake(), | ||
warn: sinon.fake(), | ||
error: spyLoggerError, | ||
}); | ||
setGlobalErrorHandler(handler); | ||
|
||
collectorTraceExporter.export(spans, () => { | ||
const response = spyLoggerError.args[0][0] as string; | ||
|
||
assert.ok(response.includes('"code":"400"')); | ||
|
||
assert.strictEqual(spyBeacon.callCount, 0); | ||
collectorTraceExporter.export(spans, result => { | ||
assert.deepStrictEqual(result.code, ExportResultCode.FAILED); | ||
assert.ok(result.error?.message.includes('Failed to export')); | ||
done(); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on what the collector report (which itself depend on upstream exporters) you can have a empty text. I prefered to opt for this generic text so user get an error message every time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xhr.status
already is passed toCollectorExporterError
. Maybe it is better to havexhr.responseText || "Failed to export with XHR"
?