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

OpenTelemetry Support #101

Merged
merged 167 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 150 commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
c8af844
Initialize OpenTelemetry SDK
Jan 7, 2022
1cbd360
Create OpenTelemetry root and middleware spans
Jan 10, 2022
f983b19
Add exit handlers for otel
Jan 10, 2022
2f04ea1
Set traceparent and tracestate on the active otel context
Jan 10, 2022
03318f8
Add otel imports to prelude
Jan 13, 2022
03fbcec
Refactor grpc switching logic
Jan 13, 2022
630c2fb
Use isHoneycomb/isOtel everywhere, including prelude
Jan 18, 2022
b432e19
Export beeline by default
Jan 18, 2022
228925b
Use OpenTelemetry semantic attributes
Jan 18, 2022
383fb3c
Move isHoneycomb/isOtel tests to prelude
Jan 18, 2022
2f091db
Replace type guards with unsafe casts, yolo
Jan 18, 2022
58f904e
Configure sampler
Jan 18, 2022
8ed6ac5
Switch from @opentelemetry/node to @opentelemetry/sdk-trace-node
Jan 18, 2022
3b06e91
Fix deprecation warning
Jan 18, 2022
745ad10
Use individual node instrumentations
Jan 18, 2022
5a5a3f7
Change default port to 8000
Jan 19, 2022
fa6b642
Update dependencies.ron, clean up unused dependency
Jan 19, 2022
8a0ef1e
Add @opentelemetry/api dependency
Jan 19, 2022
730e46c
set up W3CTraceContextPropagator
Jan 19, 2022
eb55786
Pretest hook to check typescript types
Jan 19, 2022
1f608a4
Simplify ts check script
Jan 19, 2022
608c835
Break otel functionality into unit-test-able functions
Jan 19, 2022
e8df3c3
TODOs for instrumentation modules
Jan 19, 2022
00c7792
Wrap honeycomb env var normalization in a function
Jan 19, 2022
d3769c2
Clean up tap setup in prelude
Jan 19, 2022
108e65c
Remove a bunch of crufty instrumentations and respect postgres + redi…
Jan 19, 2022
7d4694f
a bunch of otel unit tests
Jan 20, 2022
a28ea9e
t.equals -> t.equal (the former is deprecated)
Jan 20, 2022
8d40ccf
fix: Add v to version for error-produced urls
Jun 28, 2021
2572a08
whack-a-mole deprecated tap APIs
Jan 20, 2022
111ea8f
Don't import middleware/test in prelude tests
Jan 20, 2022
337fa0a
Resolve promise on error when closing parent span
Jan 20, 2022
8ce260c
Remove testing stubs from honeycomb middleware
Jan 20, 2022
93d7453
Fix template bug
Jan 20, 2022
1d7ab2b
Fix syntax error in dependencies.ron
Jan 20, 2022
bb8f347
push honeycomb into core module
Jan 21, 2022
1cd569a
Move honeycomb core code out of prelude.ts
Jan 22, 2022
b09d2d8
build succeeds! but beelines are broken in the middleware layer, womp…
Jan 28, 2022
1c028b8
Don't try to open/close spans when honeycomb isn't even initialized
Jan 28, 2022
d51d7bd
SMOKE TESTS PASSING
Jan 28, 2022
e76f6c0
Remove otel functionality to create more manageable pull request
Jan 31, 2022
9fc7573
Remove otel deps
Jan 31, 2022
8333ff6
Test the honeycomb trace span name logic
Jan 31, 2022
15bf3b0
boltzmann-cli npm package will now run x64 darwin build on arm
Jan 31, 2022
4669875
Start the trace *after* handling the ping route
Feb 8, 2022
9004caa
Update middleware.ts to use honeycomb abstraction
Feb 8, 2022
6a8065b
Revert "Remove otel deps"
Feb 8, 2022
8148e4e
Revert "Remove otel functionality to create more manageable pull requ…
Feb 8, 2022
72c46e2
rename otlp to otel throughout
Feb 8, 2022
77425c3
Remove search querystring from trace span names
Feb 8, 2022
c902ec7
Use HTTP_CLIENT_IP instead of NET_PEER_IP
Feb 8, 2022
7c1fd0e
Set span kind to SERVER
Feb 8, 2022
dcacaab
Clean up trace propagation code
Feb 8, 2022
1e2336d
Fix W3CTraceContextPropagator import
Feb 8, 2022
2c1c0a2
update core/middleware to use honeycomb facade API
Feb 8, 2022
8270892
Failing test for honeycomb/otel instrumentation
Feb 15, 2022
86959cf
Respect doNotTrace and fill in test asserts
Feb 16, 2022
036e4d6
Attempt to plumb up contexts better
Feb 16, 2022
25a0a47
spruced up the test trace propagator
Feb 17, 2022
802497d
Extra log lines for honeycomb tracing (parent/child spans not connect…
Feb 17, 2022
d7b5f28
Refactor honeycomb mocking - tests should all use the same mock objec…
Feb 21, 2022
c198945
Move span/trace up/down logic back into middleware
Feb 21, 2022
fa09223
Traces are now connecting and have the correct service.name
Feb 21, 2022
83a030d
ignore noisy http auto-instrumentation
Feb 21, 2022
e972aa5
WE HAVE INWARD PROPAGATION
Feb 22, 2022
d2f37a8
rename otelAPI to otel (for convenience)
Feb 22, 2022
9920a7b
Minor cleanup/refactors
Feb 22, 2022
3a64787
remove top-level trace span in non-test mode
Feb 22, 2022
b231ef7
Remove explicit trace context propagator (w3c works automatically)
Feb 22, 2022
0a1993a
Remove spans array and use closures instead
Feb 22, 2022
a4e0cbd
nudge span context property def to make js build happy
Feb 22, 2022
36bb26d
Fill in otel trace URL params
Feb 22, 2022
d66a197
Use bole for logging in honeycomb middleware
Feb 22, 2022
6f1c24e
honeycomb-related logging uses bole when available
Feb 22, 2022
86a34b6
type for logger
Feb 22, 2022
22e76ff
Organization/cleanup of core/honeycomb.ts
Feb 22, 2022
8243a44
Refactor how honeycomb mock is created
Feb 22, 2022
a8128a7
Use the traceparent header for the context ID if available
Feb 22, 2022
7994b8b
context.addTraceAttributes method
Feb 22, 2022
3108ced
scope otel "trace" attributes to "app." + note on traces vs spans
Feb 22, 2022
38be208
Fix setting otel "trace" attributes - strike that, reverse it
Feb 22, 2022
37bf8d0
Upgrade actions from node 12.x to 16.x
Feb 22, 2022
baceffd
Use node action v2
Feb 22, 2022
b971cca
Only add properties to otel trace span if defined
Feb 22, 2022
ec3b885
Fixes to make dispensary-dashboard build happy
Feb 22, 2022
d4be00f
Update honeycomb-beeline.d.ts in build
Feb 22, 2022
059aeb0
Make dispensary-dashboard happy with honeycomb-beeline.d.ts formatting
Feb 22, 2022
2233ef8
Naively upgrade typescript-eslint libraries to fix huge warning in co…
Feb 22, 2022
0aa1ec8
Improved comments
Feb 23, 2022
70cbe69
Add some extra trace attributes
Feb 23, 2022
2e34783
Refactor "trace attributes" feature
Feb 23, 2022
9885913
use otel.context.with instead of carrying spans on boltzmann context
Feb 23, 2022
db3e113
Wrap honeycomb logging setup in if-block + add deprecation warning
Feb 23, 2022
bc3bf75
Minor otel middleware bugfixes
Feb 23, 2022
dfd0327
Remove addTraceAttributes helper
Feb 24, 2022
2fe3662
Improve logging
Feb 24, 2022
bc4c6b7
Automatically append service_name and trace_type to every span
Feb 24, 2022
c5e0cf9
Silly templating bug
Feb 24, 2022
a7a9e5f
Test that traceExporter respects url
Feb 25, 2022
b820188
Improved otel logging
Feb 25, 2022
704ed28
imports/exports match between honeycomb + prelude
Feb 25, 2022
b7ded9a
Mock the span in the test instead of as a fallback
Feb 25, 2022
bed27e6
Fix honeycomb export
Feb 25, 2022
a7e1695
Honeycomb logging only generated in debug/dev build
Feb 25, 2022
c2f7c34
Honeycomb logging fixes
Feb 25, 2022
07ffbbd
Update documentation for OpenTelemetry support
Feb 25, 2022
9547ae2
Update examples to use current release build
Feb 25, 2022
5387876
Bump to 0.6.0 and fill out changelog fields
Feb 25, 2022
77371a7
Expand middleware test to cover handlers
Feb 25, 2022
ac971ba
Regenerate all examples
Feb 25, 2022
1f7c140
Respect the same defaults as vanilla beelines
Feb 26, 2022
4436a85
Don't write debug feature to package.json
Feb 26, 2022
363fae0
Manage node version with volta
Feb 26, 2022
edb00e2
Switch from GRPC exporter to HTTP exporter - need to update env vars
Feb 28, 2022
b3f9ed4
Switch on OTEL_* env vars instead of HONEYCOMB_API_HOST
Feb 28, 2022
7a0a172
Use otel diagnostic logger
Mar 1, 2022
1271b55
Clean up SDK setup, get rid of errors
Mar 1, 2022
cf9b6ed
Button up otel logging
Mar 1, 2022
1947b2c
Remove debug flag from boltzmann generator
Mar 1, 2022
79d34a1
Support ALL THREE OTLP trace exporters
Mar 1, 2022
f372189
Improved comments
Mar 1, 2022
5e61afb
More comments
Mar 1, 2022
7bc9563
Only do otel logging if LOG_LEVEL === "debug"
Mar 1, 2022
aeb6f6a
Improved comments for OTEL_EXPORTER_OTLP_ENDPOINT
Mar 1, 2022
ffe9d6f
one OVER sampling rate
Mar 1, 2022
2d416d4
bugfix - use proto exporter when protocol is http/protobuf
Mar 1, 2022
445d319
Let otel use the automatically-configured sampler
Mar 1, 2022
6b3f8f2
Make HONEYCOMB_WRITEKEY optional for otel
Mar 1, 2022
5606948
Fix volta feature bug
Mar 1, 2022
73076f7
Respect OTEL_SERVICE_NAME
Mar 1, 2022
95a066d
More tests for parseEnv
Mar 1, 2022
6d696e8
Move honeycomb singleton out of prelude
Mar 1, 2022
043a057
Don't run honeycomb init inside test block, oops
Mar 1, 2022
d00fcb6
Rename the default otel http span
Mar 2, 2022
aec735f
Remove comment
Mar 2, 2022
cff8da6
Add span attributes for CORS origin
Mar 2, 2022
a2649b6
Make honeycomb settings logging more useful for beelines
Mar 3, 2022
5ebf5c2
Set the initialized flag when beeline
Mar 3, 2022
96407b0
Minor logging tweaks
Mar 3, 2022
025b1c2
Some gaps on beeline trace_type/service.name attributes
Mar 3, 2022
3c21e10
Rename boltzman.honeycomb.trace_type to honeycomb.trace_type
Mar 4, 2022
12a9eb4
Use {{ version }} instead of hard-coding 1.0
Mar 7, 2022
c616d61
Remove stale comment
Mar 7, 2022
00ad225
Update stale test description
Mar 7, 2022
646ec88
Remove stale comment
Mar 7, 2022
3434404
Update honeycomb middleware configuration docs
Mar 7, 2022
68df834
Tweaks to honeycomb middleware docs
Mar 7, 2022
69c351a
Wrap honeycomb tracing in cors with template if block
Mar 7, 2022
c3c582d
Fix tests
Mar 7, 2022
1f8a01d
fix typed example build
Mar 7, 2022
58353e8
Remove ctor def in span processor + comment onEnd
Mar 17, 2022
131950c
Comment update
jfhbrook-at-work Mar 17, 2022
1399cd7
Improved documentation and comments
Mar 17, 2022
dd448f9
Use INTERNAL SpanKind instead of SERVER
Mar 21, 2022
193214b
Document factory overrides as internal
Mar 21, 2022
4aaacc3
Remove graceful shutdown code
Mar 21, 2022
b602bd3
Expose boltzmann version in /monitor/status
Mar 21, 2022
b767076
Remove compatibility + trace_type attributes
Mar 21, 2022
5502b7e
Install volta during tests
Mar 24, 2022
a4085e0
Try a different strategy to add volta to the PATH
Mar 25, 2022
af6d060
why isnt volta working??
Mar 25, 2022
b84a31e
Try running "volta install node"
Mar 28, 2022
fcdcd07
Try installing volta during the build step
Mar 28, 2022
59a8e92
Remove volta from --all
Mar 28, 2022
8873022
Clean up release build task
Mar 28, 2022
a02f344
updated package.json
Mar 28, 2022
2405c2b
Handle peer dependencies shenanigans as best we can
Mar 28, 2022
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
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
node-version: '12'
node-version: '16'
- name: download release contents
run: |
tag=${{ github.ref }}
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
const fs = require('fs')
const spawnSync = require('child_process').spawnSync

const executable = path.join(__dirname, 'boltzmann_' + os.arch() + '_' + os.platform()) + (os.platform() === 'win32' ? '.exe' : '')
const executable = path.join(__dirname, 'boltzmann_' + (os.platform() === 'darwin' ? 'x64' : os.arch()) + '_' + os.platform()) + (os.platform() === 'win32' ? '.exe' : '')
jfhbrook-at-work marked this conversation as resolved.
Show resolved Hide resolved

if (!fs.existsSync(executable)) {
console.error("Sorry, boltzmann is not yet supported on %s", os.platform())
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Use Node.js 12.x
- name: Use Node.js ${{ matrix.node_version }}
jfhbrook-at-work marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/[email protected]
with:
node-version: ${{ matrix.node_version }}
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["C J Silverio <[email protected]>", "Chris Dickinson <[email protected]>"]
edition = "2021"
name = "boltzmann"
version = "0.5.3"
version = "0.6.0"
documentation = "https://www.boltzmann.dev/en/docs/latest/"
description = "A scaffolder for Boltzmann.js http service projects."
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ For example, to scaffold with the defaults:
projects|⇒ npx boltzmann-cli hello
```

A complete project is provided for you, with useful package run scripts and linting. To run: `./boltzmann.js`. And to view the response: `curl http://localhost:5000/hello/world`. Want to know more? [Check the docs!](https://www.boltzmann.dev/en/docs/latest/)
A complete project is provided for you, with useful package run scripts and linting. To run: `./boltzmann.js`. And to view the response: `curl http://localhost:8000/hello/world`. Want to know more? [Check the docs!](https://www.boltzmann.dev/en/docs/latest/)
jfhbrook-at-work marked this conversation as resolved.
Show resolved Hide resolved

## Team

Expand Down
11 changes: 11 additions & 0 deletions bin/checkts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
jfhbrook-at-work marked this conversation as resolved.
Show resolved Hide resolved

set -e

if [ ! -e node_modules ]; then
npm ci
else
npm i
fi

node_modules/.bin/tsc --noEmit --project ./tsconfig-build-js.json
5 changes: 4 additions & 1 deletion docs/content/reference/02-handlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,15 @@ async function host(context) {
### `id`

{{ changelog(version = "0.0.0") }}
- **Changed in 0.6.0:** Use `traceparent` as the `id` when available.
{% end %}

A unique string identifier for the request for tracing purposes. The value is
drawn from:

1. `x-honeycomb-trace`
1. `x-honeycomb-trace` (via Honeycomb beeline tracing)
2. `x-request-id`
3. `traceparent` (via Honeycomb OpenTelemetry tracing)
3. A generated [ship name from Iain M Bank's Culture series][culture] (e.g.: `"ROU Frank Exchange Of Views"`)

**Example use:**
Expand Down
52 changes: 39 additions & 13 deletions docs/content/reference/03-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,9 @@ Here is an example of the request logging:
```

The `id` fields in logs is the value of the request-id, available on the context object as the `id`
field. This is set by examining headers for an existing id. Boltzmann consults `x-honeycomb-trace`
and `x-request-id` before falling back to generating a request id using a short randomly-selected
string.
field. This is set by examining headers for an existing id. Boltzmann consults `x-honeycomb-trace`,
`x-request-id` and `traceparent` before falling back to generating a request id using a short
randomly-selected string.

To log from your handlers, you might write code like this:

Expand All @@ -773,19 +773,45 @@ Boltzmann automatically attaches one instance of [`route`](#route).

### `trace`

{% changelog(version="0.0.0") %}
- **Changed in 0.6.0:** Tracing now uses OpenTelemetry if any `OTEL_*` environment
variable is defined
{% end %}

This middleware is added to your service if you have enabled the `honeycomb` feature.
This feature sends trace data to the [Honeycomb](https://www.honeycomb.io) service for
deep observability of the performance of your handlers.

To configure this middleware, set the following environment variables:

- `HONEYCOMB_WRITEKEY`: the honeycomb API key to use; required to enable tracing
- `HONEYCOMB_DATASET`: the name of the dataset to send trace data to; required to enable tracing
- `HONEYCOMB_TEAM`: optional; set this to enable links to traces from error reporting
- `HONEYCOMB_SAMPLE_RATE`: optional; passed to `honeycomb-beeline` to set the sampling rate for events

The sampling rate defaults to 1 if neither sample rate env var is set. Tracing is
disabled if a write key and dataset are not provided; the middleware is still
attached but does nothing in this case.
To configure this middleware for [beeline](https://www.npmjs.com/package/honeycomb-beeline)
tracing, set the following environment variables:

- `HONEYCOMB_API_HOST`: (optional) the honeycomb API endpoint to use - defaults to localhost
- `HONEYCOMB_WRITEKEY`: the honeycomb API key to use - required to enable beeline tracing
- `HONEYCOMB_DATASET`: the name of the dataset to send trace data to - defaults to `nodejs`
- `HONEYCOMB_TEAM`: (optional) set this to enable links to traces from development error reporting
- `HONEYCOMB_SAMPLE_RATE`: (optional) passed to `honeycomb-beeline` to set the sampling rate for events - defaults to 1

The honeycomb middleware also supports
[OpenTelemetry](https://opentelemetry.io/docs/instrumentation/js/getting-started/nodejs/)
tracing over [the OTLP http/protobuf protocol](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md).
This is enabled if any `OTEL_*` environment variables are defined.

OpenTelemetry supports many, many environment variables - they document both
[common SDK environment variables](https://opentelemetry.io/docs/reference/specification/sdk-environment-variables/)
and [OTLP exporter-specific environment variables](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md),
and it's worth perusing all of them. However, if you are in a rush:

- `HONEYCOMB_WRITEKEY`: this is still used in an OpenTelemetry configuration
- `HONEYCOMB_DATASET`: this is also still used in an OpenTelemetry configuration
- `OTEL_EXPORTER_OTLP_ENDPOINT`: the API endpoint - i.e. `https://api.honeycomb.io`, or your [refinery](https://docs.honeycomb.io/manage-data-volume/refinery/) instance if using one

In you really, really want to use the default OpenTelemetry configuration,
you can set `OTEL_ENABLE=1` - this isn't meaningful for the OpenTelemetry SDKs
or OTLP exporters but will trigger the enabling of OpenTelemetry in boltzmann.

Note that OpenTelemetry tracing, while intended for use with Honeycomb, may be
used with any OTLP tracing backend. You can do this by foregoing the setting of
`HONEYCOMB_WRITEKEY` and setting `OTEL_EXPORTER_OTLP_HEADERS` to contain the
alternate headers for your backend.
jfhbrook-at-work marked this conversation as resolved.
Show resolved Hide resolved

* * *
131 changes: 78 additions & 53 deletions examples/attaching-middleware/boltzmann.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
/* eslint-disable */
/* c8 ignore file */
'use strict';
// Boltzmann v0.5.3
/**/
// Dependencies used outside of honeycomb
const bole = require("@entropic/bole");
const isDev = require("are-we-dev");
module.exports = {...module.exports, bole, isDev };
void ``;

'use strict';
// Boltzmann v0.6.0
/**/
const serviceName = _getServiceName();
function _getServiceName() {
Expand All @@ -13,6 +21,7 @@ function _getServiceName() {
return 'boltzmann';
}
}
/**/
void ``;
const ships = require("culture-ships");
void ``;
Expand All @@ -37,13 +46,11 @@ void ``;
const { Readable } = require("stream");
const querystring = require("querystring");
const { promisify } = require("util");
const isDev = require("are-we-dev");
const fmw = require("find-my-way");
const accepts = require("accepts");
const { promises: fs } = require("fs");
const crypto = require("crypto");
const http = require("http");
const bole = require("@entropic/bole");
const path = require("path");
const os = require("os");
void ``;
Expand Down Expand Up @@ -111,12 +118,16 @@ async function buildMiddleware(middleware, router) {
return rhs(await lhs);
}, Promise.resolve(router));
}
function handlerSpanName(handler) {
return `handler: ${handler.name || '<unknown>'}`;
}
async function handler(context) {
const handler = context.handler;
//
return await handler(context);
//
return await handler(context);
//
}
void ``;

void ``;
async function routes(handlers) {
Expand Down Expand Up @@ -175,6 +186,7 @@ class Context {
this.params = {};
this.id = String(request.headers['x-honeycomb-trace'] ||
request.headers['x-request-id'] ||
request.headers['traceparent'] ||
uuid.v4());
this._loadSession = async () => {
throw new Error('To use context.session, attach session middleware to your app');
Expand Down Expand Up @@ -998,18 +1010,28 @@ function handleCORS({ origins = isDev() ? '*' : String(process.env.CORS_ALLOW_OR
const includesStar = originsArray.includes('*');
return (next) => {
return async function cors(context) {
const reflectedOrigin = (includesStar
? '*'
: (originsArray.includes(String(context.headers.origin))
? context.headers.origin
: false));
const spanAttributes = {
'boltzmann.http.origin': String(context.headers.origin)
};
if (honeycomb.features.beeline) {
beeline.addContext(spanAttributes);
}
const span = otel.trace.getSpan(otel.context.active());
if (span) {
span.setAttributes(spanAttributes);
}
if (!includesStar && !originsArray.includes(String(context.headers.origin))) {
throw Object.assign(new Error('Origin not allowed'), {
[Symbol.for('status')]: 400
});
}
const response = (context.method === 'OPTIONS'
? Object.assign(Buffer.from(''), {
[Symbol.for('status')]: 204,
})
: await next(context));
response[Symbol.for('headers')] = {
...(reflectedOrigin ? { 'Access-Control-Allow-Origin': reflectedOrigin } : {}),
'Access-Control-Allow-Origin': includesStar ? '*' : context.headers.origin,
'Access-Control-Allow-Methods': [].concat(methods).join(','),
'Access-Control-Allow-Headers': [].concat(headers).join(',')
};
Expand Down Expand Up @@ -1075,13 +1097,16 @@ function enforceInvariants() {


void ``;
function log({ logger = bole(process.env.SERVICE_NAME || 'boltzmann'), level = process.env.LOG_LEVEL || 'debug', stream = process.stdout } = {}) {
function log({ logger = bole(serviceName),
//
level = process.env.LOG_LEVEL || 'debug', stream = process.stdout, } = {}) {
if (isDev()) {
const pretty = require('bistre')({ time: true });
pretty.pipe(stream);
stream = pretty;
}
bole.output({ level, stream });
void ``;
return function logMiddleware(next) {
return async function inner(context) {
const result = await next(context);
Expand Down Expand Up @@ -1109,6 +1134,7 @@ void ``;


void ``;
handlePing.doNotTrace = true;
function handlePing() {
return (next) => (context) => {
if (context.url.pathname === '/monitor/ping') {
Expand Down Expand Up @@ -1465,7 +1491,7 @@ const validate = {
*
* The `validate.body` middleware applies [JSON schema]( "https://json-schema.org/") validation to incoming
* request bodies. It intercepts the body that would be returned by
* \[`context.body`\] and validates it against the given schema, throwing a `400 Bad Request` error on validation failure. If the body passes validation it is
* \[`context.body`] and validates it against the given schema, throwing a `400 Bad Request` error on validation failure. If the body passes validation it is
* passed through.
*
* `Ajv` is configured with `{useDefaults: true, allErrors: true}` by default. In
Expand Down Expand Up @@ -1744,9 +1770,9 @@ const middleware = {
* ````
*
* The `id` fields in logs is the value of the request-id, available on the context object as the `id`
* field. This is set by examining headers for an existing id. Boltzmann consults `x-honeycomb-trace`
* and `x-request-id` before falling back to generating a request id using a short randomly-selected
* string.
* field. This is set by examining headers for an existing id. Boltzmann consults `x-honeycomb-trace`,
* `x-request-id` and `traceparent` before falling back to generating a request id using a short
* randomly-selected string.
*
* To log from your handlers, you might write code like this:
*
Expand Down Expand Up @@ -1950,44 +1976,43 @@ module.exports = {...module.exports, Context, main: runserver, middleware, body
void ``;
/* c8 ignore next */
if (require.main === module && !process.env.TAP) {
function passthrough() {
return (next) => (context) => next(context);
}
runserver({
middleware: _requireOr('./middleware', [])
.then(_processMiddleware)
.then((mw) => {
//
//
const acc = [];
//
//
acc.push(handlePing);
//
//
acc.push(log);
//
//
acc.push(...mw);
//
acc.push(handleStatus);
//
return acc.filter(Boolean);
}),
})
.then((server) => {
server.listen(Number(process.env.PORT) || 5000, () => {
const addrinfo = server.address();
if (!addrinfo) {
return;
}
bole('boltzmann:server').info(`now listening on port ${typeof addrinfo == 'string' ? addrinfo : addrinfo.port}`);
//
runserver({
middleware: _requireOr('./middleware', [])
.then(_processMiddleware)
.then((mw) => {
//
//
const acc = [];
//
acc.push(handlePing);
//
//
//
acc.push(log);
//
//
acc.push(...mw);
//
acc.push(handleStatus);
//
return acc.filter(Boolean);
}),
})
.then((server) => {
server.listen(Number(process.env.PORT) || 8000, () => {
const addrinfo = server.address();
if (!addrinfo) {
return;
}
bole('boltzmann:server').info(`now listening on port ${typeof addrinfo == 'string' ? addrinfo : addrinfo.port}`);
});
})
.catch((err) => {
console.error(err.stack);
process.exit(1);
});
})
.catch((err) => {
console.error(err.stack);
process.exit(1);
});
//
}


Loading