From 0762e411c91b876b33a949e8399cf3cbe84aa4b7 Mon Sep 17 00:00:00 2001 From: Lenny Burdette Date: Thu, 7 Mar 2019 17:10:40 -0800 Subject: [PATCH] feat: support unix sockets for requests --- src/writer.js | 11 ++++++++--- test/writer.spec.js | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/writer.js b/src/writer.js index 5f179b2ac19..e90c6e2b7a5 100644 --- a/src/writer.js +++ b/src/writer.js @@ -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: { @@ -71,6 +68,14 @@ class Writer { } } + if (this._url.protocol === 'unix:') { + options.socketPath = this._url.pathname + } else { + options.protocol = this._url.protocol + options.hostname = this._url.hostname + options.port = this._url.port + } + log.debug(() => `Request to the agent: ${JSON.stringify(options)}`) platform diff --git a/test/writer.spec.js b/test/writer.spec.js index f7ca815abb3..0242f65c008 100644 --- a/test/writer.spec.js +++ b/test/writer.spec.js @@ -1,5 +1,7 @@ 'use strict' +const URL = require('url-parse') + describe('Writer', () => { let Writer let writer @@ -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 + }) + }) + }) }) })