-
Notifications
You must be signed in to change notification settings - Fork 171
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
Added agent option to http transport #439
Changes from 5 commits
d5fbc55
2add964
4109619
9199c5f
7a6b616
86f4c73
6e391ba
c85d8c2
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 |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import {Agent as HttpAgent } from 'http'; | ||
import {Agent as HttpsAgent} from 'https'; | ||
import {JsonEncoder, Logger, model} from 'zipkin'; | ||
|
||
type Agent = HttpAgent | HttpsAgent; | ||
|
||
declare class HttpLogger implements Logger { | ||
constructor(options: { | ||
endpoint: string, | ||
httpInterval?: number, | ||
jsonEncoder?: JsonEncoder, | ||
httpTimeout?: number, | ||
timeout?: number, | ||
maxPayloadSize?: number, | ||
headers?: { [name: string]: any }, | ||
agent?: Agent | (() => Agent), | ||
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. is Let's add typescript and javascript tests for this parameter to make sure someone later doesn't accidentally break what you need. 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.
This follows node-fetch which will accept an HTTP(S) Agent or a function which returns a HTTP(S) Agent I have also added typescript tests, to ensure the current functionality & also the newly added agent types. |
||
log?: Console | ||
}); | ||
|
||
logSpan(span: model.Span): void; | ||
} | ||
export {HttpLogger}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { expect } from 'chai'; | ||
|
||
import {Agent as HttpAgent } from 'http'; | ||
import {Agent as HttpsAgent} from 'https'; | ||
import {jsonEncoder} from 'zipkin'; | ||
|
||
import { HttpLogger } from 'zipkin-transport-http'; | ||
|
||
describe('HttpLogger', () => { | ||
it('should have correct type', () => { | ||
const options = { | ||
endpoint: 'testEndpoint', | ||
httpInterval: 1000, | ||
jsonEncoder: jsonEncoder.JSON_V1, | ||
timeout: 0, | ||
maxPayloadSize: 0, | ||
headers: {}, | ||
agent: new HttpAgent(), | ||
log: console | ||
}; | ||
const httpLogger: HttpLogger = new HttpLogger(options); | ||
|
||
expect(httpLogger.logSpan).to.be.a('function'); | ||
}); | ||
|
||
it('should accept Http(s) Agent or function which returns Agent', () => { | ||
const agents = [new HttpAgent(), new HttpsAgent(), () => new HttpAgent(), () => new HttpsAgent()]; | ||
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. so this test makes sure it doesn't crash in the constructor. am I understanding that right? I wonder if it would crash later. It might be confusing to have a test without assertions I mean.. wdyt? 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. Ya it's testing the constructor. I've added an expect statement to confirm Beyond that, it is only being forwarded to the fetch call. Ideally I could confirm that fetch is being called with the agent, however due to the |
||
|
||
agents.forEach(agent => { | ||
const options = { | ||
endpoint: 'testEndpoint', | ||
agent | ||
}; | ||
const httpLogger: HttpLogger = new HttpLogger(options); | ||
}); | ||
}); | ||
}); |
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.
Updated this to process
test-type/*.test.ts
tests in all packages. This reflects the second mocha command which usestest/mocha-types.opts
and attempts to run test-type tests in all packages.