Skip to content
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

feat: support unix sockets for requests #479

Merged
merged 1 commit into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions src/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ class Writer {

_request (data, count) {
const options = {
protocol: this._url.protocol,
hostname: this._url.hostname,
port: this._url.port,
path: '/v0.4/traces',
method: 'PUT',
headers: {
Expand All @@ -71,6 +68,14 @@ class Writer {
}
}

if (this._url.protocol === 'unix:') {
options.socketPath = this._url.pathname
} else {
options.protocol = this._url.protocol
rochdev marked this conversation as resolved.
Show resolved Hide resolved
options.hostname = this._url.hostname
options.port = this._url.port
}

log.debug(() => `Request to the agent: ${JSON.stringify(options)}`)

platform
Expand Down
18 changes: 18 additions & 0 deletions test/writer.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const URL = require('url-parse')

describe('Writer', () => {
let Writer
let writer
Expand Down Expand Up @@ -176,5 +178,21 @@ describe('Writer', () => {
done()
})
})

context('with the url as a unix socket', () => {
beforeEach(() => {
url = new URL('unix:/path/to/somesocket.sock')
writer = new Writer(prioritySampler, url, 3)
})

it('should make a request to the socket', () => {
writer.append(span)
writer.flush()

expect(platform.request).to.have.been.calledWithMatch({
socketPath: url.pathname
})
})
})
})
})