Skip to content
Open
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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ hot-shots is a Node.js client library for StatsD, DogStatsD (Datadog), and Teleg
The library supports multiple transport protocols:
- **UDP**: Default protocol using dgram sockets
- **TCP**: Persistent connection with graceful error handling
- **UDS**: Unix Domain Sockets (requires unix-dgram optional dependency)
- **UDS**: Unix Domain Sockets (requires unix-dgram-rs dependency)
- **Stream**: Raw stream protocol for custom transports

### Client Architecture
Expand Down
21 changes: 4 additions & 17 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ const net = require('net');
const dns = require('dns');
const os = require('os');
const util = require('util');
const unixDgram = require('unix_dgram_rs');
const { PROTOCOL } = require('./constants');

const debug = util.debuglog('hot-shots');

// Imported below, only if needed
let unixDgram;

const UDS_PATH_DEFAULT = '/var/run/datadog/dsd.socket';

/**
Expand Down Expand Up @@ -231,21 +229,10 @@ const createUdpTransport = args => {
/**
* Creates a Unix Domain Socket (UDS) transport for local IPC metric delivery.
* Implements automatic retry logic with exponential backoff for EAGAIN and congestion errors.
* Requires the optional unix-dgram dependency to be installed.
* @param {Object} args - Configuration options including path and udsRetryOptions
* @returns {Transport} A transport object implementing the Transport interface
*/
const createUdsTransport = args => {
try {
// This will not always be available, as noted in the error message below
unixDgram = require('unix-dgram'); // eslint-disable-line global-require
} catch (err) {
throw new Error(
'The library `unix_dgram`, needed for the uds protocol to work, is not installed. ' +
'You need to pick another protocol to use hot-shots. ' +
'See the hot-shots README for additional details.'
);
}
// Only retry-related options live here now
const udsOpts = args.udsRetryOptions || {};
const udsPath = args.path ? args.path : UDS_PATH_DEFAULT;
Expand Down Expand Up @@ -284,8 +271,8 @@ const createUdsTransport = args => {
};

/**
* Checks if an error is a congestion error from unix-dgram.
* unix-dgram returns an internal 'congestion' error (err === 1) via callback.
* Checks if an error is a congestion error from unix_dgram_rs.
* unix_dgram_rs returns an internal 'congestion' error (err === 1) via callback.
* @param {Error} err - The error to check
* @returns {boolean} True if the error is a congestion error
*/
Expand Down Expand Up @@ -351,7 +338,7 @@ const createUdsTransport = args => {
socket.emit('close');
},
unref: () => {
throw new Error('unix-dgram does not implement unref for sockets');
throw new Error('unix_dgram_rs does not implement unref for sockets');
}
};
};
Expand Down
Loading
Loading