Skip to content

Commit

Permalink
Merge pull request #154 from JaniAnttonen/development
Browse files Browse the repository at this point in the history
Create a new release v6.1.1
  • Loading branch information
JaniAnttonen authored Apr 15, 2024
2 parents b650180 + 378cdd9 commit 503972f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import TransportStream from "winston-transport";
import http from 'http';
import https from 'https';

declare interface LokiTransportOptions extends TransportStream.TransportStreamOptions{
host: string;
Expand All @@ -12,6 +14,8 @@ declare interface LokiTransportOptions extends TransportStream.TransportStreamOp
replaceTimestamp?: boolean,
gracefulShutdown?: boolean,
timeout?: number,
httpAgent?: http.Agent | boolean;
httpsAgent?: https.Agent | boolean;
onConnectionError?(error: unknown): void
}

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class LokiTransport extends Transport {
onConnectionError: options.onConnectionError,
replaceTimestamp: options.replaceTimestamp !== false,
gracefulShutdown: options.gracefulShutdown !== false,
timeout: options.timeout
timeout: options.timeout,
httpAgent: options.httpAgent,
httpsAgent: options.httpsAgent
})

this.useCustomFormat = options.format !== undefined
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "winston-loki",
"version": "6.1.0",
"version": "6.1.1",
"description": "A Winston transport for Grafana Loki",
"keywords": [
"winston",
Expand Down
2 changes: 1 addition & 1 deletion src/batcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class Batcher {
}

// Send the data to Grafana Loki
req.post(this.url, this.contentType, this.options.headers, reqBody, this.options.timeout)
req.post(this.url, this.contentType, this.options.headers, reqBody, this.options.timeout, this.options.httpAgent, this.options.httpsAgent)
.then(() => {
// No need to clear the batch if batching is disabled
logEntry === undefined && this.clearBatch()
Expand Down
6 changes: 4 additions & 2 deletions src/requests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const http = require('http')
const https = require('https')

const post = async (lokiUrl, contentType, headers = {}, data = '', timeout) => {
const post = async (lokiUrl, contentType, headers = {}, data = '', timeout, httpAgent, httpsAgent) => {
// Construct a buffer from the data string to have deterministic data size
const dataBuffer = Buffer.from(data, 'utf8')

Expand All @@ -14,6 +14,7 @@ const post = async (lokiUrl, contentType, headers = {}, data = '', timeout) => {
return new Promise((resolve, reject) => {
// Decide which http library to use based on the url
const lib = lokiUrl.protocol === 'https:' ? https : http
const agent = lokiUrl.protocol === 'https:' ? httpsAgent : httpAgent

// Construct the node request options
const options = {
Expand All @@ -22,7 +23,8 @@ const post = async (lokiUrl, contentType, headers = {}, data = '', timeout) => {
path: lokiUrl.pathname,
method: 'POST',
headers: Object.assign(defaultHeaders, headers),
timeout: timeout
timeout: timeout,
agent: agent
}

// Construct the request
Expand Down

0 comments on commit 503972f

Please sign in to comment.