Skip to content

Commit

Permalink
first version worth mentioning
Browse files Browse the repository at this point in the history
  • Loading branch information
paed01 committed Nov 12, 2023
1 parent c632b75 commit 05adc05
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
56 changes: 43 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,33 @@ Build transport stream function.
* `connectionString`: Application Insights connection string or instrumentation key
* `config`: optional Application Insights Telemetry client config
* `destination`: optional destination stream, makes build ignore the above options
* `ignoreKeys`: optional pino ignore keys, defaults to `['hostname', 'pid', 'level', 'time', 'msg']`
* `ignoreKeys`: optional pino ignore keys, used to filter telemetry properties, defaults to `['hostname', 'pid', 'level', 'time', 'msg']`
- `TelemetryTransformation`: optional transformation stream extending [TelemetryTransformation](#class-telemetrytransformationoptions-config)

### `class TelemetryTransformation(options[, config])`

Telemetry transformation stream. Transforms pino log record to [Telemetry:ish](#telemetrish-object) object.

- `constructor(options[, config])`
* `options`: transform stream options, `{ objectMode: true }` is always set
* `config`: optional config object
- `ignoreKeys`: optional pino ignore keys as string array
- `_transform(chunk, encoding, callback)`
- `convertToTelemetry(chunk)`: convert pino log record string or object to [telemetry:ish object](#telemetrish-object)
- `convertLevel(level)`: map pino log level number to `Contracts.SeverityLevel`
- `extractProperties(line, ignoreKeys)`: extract properties from log line
* `line`: log line record object
* `ignoreKeys`: configured ignore keys
- properties:
* `ignoreKeys`: configured ignore keys, defaults to `['hostname', 'pid', 'level', 'time', 'msg']`

#### Telemetrish object

- `severity`: pino log level mapped to application insights `Contracts.SeverityLevel`
- `severity`: pino log level mapped to application insights severeity level, i.e. `Contracts.SeverityLevel`
- `msg`: log message string
- `properties`: telemetry properties object, filtered through ignore keys
- `exception?`: logged Error if any
- `[k: string]`: any other properties
- `[k: string]`: any other properties that facilitate telemetry logging

### `class FakeApplicationInsights(setupString)`

Expand All @@ -61,7 +74,7 @@ Intercept calls to application insights.
- `expectExceptionData()`: Expect tracked exception, returns [`Promise<FakeCollectData>`](#fakecollectdata)
- `expectEventType(telemetryType: string)`: Expect tracked telemetry type, returns [`Promise<FakeCollectData>`](#fakecollectdata)
* `telemetryType`: Telemetry type string
- `expect(count = 1)`: Expect tracked telemetrys, returns list of [`Promise<FakeCollectData[]>`](#fakecollectdata)
- `expect(count = 1)`: Expect tracked telemetrys, returns promise with list of [`FakeCollectData`](#fakecollectdata)
* `count`: wait for at least tracked telemetrys before returning, default is 1
- `reset()`: Reset expected faked Application Insights calls, calls `nock.cleanAll`
- properties:
Expand Down Expand Up @@ -119,19 +132,36 @@ describe('test logger', () => {

#### `FakeCollectData`

- `uri`: string;
- `method`: string;
An object representing the request sent to application insights.

- `uri`: request uri
- `method`: request method
- `headers`: request headers object
- `body`:
* `ver`: some version number
* `sampleRate`: sample rate number
* `tags`: object with tags
* `ver`: some version number, usually 1
* `sampleRate`: sample rate number, usually 100
* `tags`: object with tags, tag names can be inspected under `TelemetryClient.context.keys`, e.g:
- `ai.application.ver`: your package.json version
- `ai.device.id`: ?
- `ai.cloud.roleInstance`: computer hostname?
- `ai.device.osVersion`: computer os
- `ai.cloud.role`: Web maybe?
- `ai.device.osArchitecture`: probably x64
- `ai.device.osPlatform`: os platform, as the name says
- `ai.internal.sdkVersion`: applicationinsights package version, e.g. `node:2.9.1`
- `[tag name]`: any other tag found under `TelemetryClient.context.keys`
* `data`:
- `baseType`: telemetry type string
- `baseData`:
* `ver`: number
* `ver`: some version number, usually 2 for some reason
* `properties`: telemetry properties object
* `[x: string]`: any other telemetry
- `iKey`: instrumentation key string
- `name`: string
* `[message]`: logged message when tracking trace
* `[severityLevel]`: applicationinsights severity level number when tracking trace and exception
* `[exceptions]`: list of exceptions when tracking exception
- `message`: error message
- `hasFullStack`: boolean, true
- `parsedStack`: stack parsed as objects
* `[x: string]`: any other telemetry property
- `iKey`: applicationinsights instrumentation key
- `name`: some ms name with iKey and the tracked type
- `time`: log time
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0dep/pino-applicationinsights",
"version": "0.0.7",
"version": "0.1.0",
"description": "Pino applicationinsights transport",
"type": "module",
"module": "./src/index.js",
Expand Down Expand Up @@ -56,6 +56,7 @@
"@types/mocha": "^10.0.3",
"@types/node": "^16.18.60",
"applicationinsights": "^2.9.0",
"applicationinsights-opentelemetry": "npm:applicationinsights@^3.0.0-beta.10",
"c8": "^8.0.1",
"chai": "^4.3.10",
"chronokinesis": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion test/src/log-transport-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('log transport', () => {
expect(exception.parsedStack[0].fileName, 'stack file name').to.include(filePath);
});

it('logs time taken from log record', async () => {
it('logs time extracted from log record', async () => {
ck.freeze();

const expectMessage = fakeAI.expectMessageData();
Expand Down

0 comments on commit 05adc05

Please sign in to comment.