-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: initial #1
Merged
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9bad756
feat: initial commit
metcoder95 1f0230b
chore: standardise settings
metcoder95 a477911
feat: initial implementation
metcoder95 6e7b228
feat: support more cases
metcoder95 8f36917
chore: small helper
metcoder95 f672513
refactor: change attributes of parent span
metcoder95 df998b6
feat: propagate context
metcoder95 c656a90
feat: add support for not found handler
metcoder95 26979f6
feat: better support for onError
metcoder95 9e41010
fix: adjust implementation
metcoder95 c0ba772
test: extend for encapsulation
metcoder95 18ac98c
test: remove leftovers
metcoder95 57e5b50
refactor:naming
metcoder95 9e352a7
feat(types): add typescript
metcoder95 17ba9ba
test: remove redundant checks
metcoder95 a591e46
docs: add README
metcoder95 66f7bac
types; adjust typing
metcoder95 4841fd4
docs: adjust
metcoder95 3176e83
refactor: small refactor
metcoder95 97d9746
test: add ts
metcoder95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Set default behavior to automatically convert line endings | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "monthly" | ||
open-pull-requests-limit: 10 | ||
|
||
- package-ecosystem: "npm" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
open-pull-requests-limit: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Number of days of inactivity before an issue becomes stale | ||
daysUntilStale: 15 | ||
# Number of days of inactivity before a stale issue is closed | ||
daysUntilClose: 7 | ||
# Issues with these labels will never be considered stale | ||
exemptLabels: | ||
- "discussion" | ||
- "feature request" | ||
- "bug" | ||
- "help wanted" | ||
- "plugin suggestion" | ||
- "good first issue" | ||
# Label to use when marking an issue as stale | ||
staleLabel: stale | ||
# Comment to post when marking an issue as stale. Set to `false` to disable | ||
markComment: > | ||
This issue has been automatically marked as stale because it has not had | ||
recent activity. It will be closed if no further activity occurs. Thank you | ||
for your contributions. | ||
# Comment to post when closing a stale issue. Set to `false` to disable | ||
closeComment: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
- next | ||
- 'v*' | ||
paths-ignore: | ||
- 'docs/**' | ||
- '*.md' | ||
pull_request: | ||
paths-ignore: | ||
- 'docs/**' | ||
- '*.md' | ||
|
||
jobs: | ||
test: | ||
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5 | ||
with: | ||
lint: true | ||
license-check: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
# Vim swap files | ||
*.swp | ||
|
||
# macOS files | ||
.DS_Store | ||
|
||
# Clinic | ||
.clinic | ||
|
||
# lock files | ||
bun.lockb | ||
package-lock.json | ||
pnpm-lock.yaml | ||
yarn.lock | ||
|
||
# editor files | ||
.vscode | ||
.idea | ||
|
||
#tap files | ||
.tap/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Fastify | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,80 @@ | ||
# otel | ||
OpenTelemetry instrumentation library. | ||
# @fastify/otel | ||
|
||
[![CI](https://github.com/fastify/otel/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/otel/actions/workflows/ci.yml) | ||
|
||
<!-- [![NPM version](https://img.shields.io/npm/v/@fastify/otel.svg?style=flat)](https://www.npmjs.com/package/fastify-plugin) --> | ||
|
||
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard) | ||
|
||
`fastify-plugin` is a plugin helper for [Fastify](https://github.com/fastify/fastify). | ||
|
||
OpenTelemetry auto-instrumentation library. | ||
metcoder95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Install | ||
|
||
```sh | ||
npm i @fastify/otel | ||
``` | ||
|
||
## Usage | ||
|
||
`@fastify/otel` works as a metric creator as well as instrumentation for you fastify application. | ||
metcoder95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Its usage requires to be set before you start defining your routes and other plugins in order to cover up the most of your fatify server. | ||
metcoder95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- It automatically wraps the main request handler | ||
- Instruments all route hooks (defined at instance and route definition level) | ||
- `onRequest` | ||
- `preParsing` | ||
- `preValidation` | ||
- `preHandler` | ||
- `preSerialization` | ||
- `onSend` | ||
- `onResponse` | ||
- `onError` | ||
- Instruments automatically custom 404 Not Found handler | ||
|
||
Example: | ||
|
||
```js | ||
// ... in your OTEL setup | ||
const FastifyInstrumentation = require('@fastify/otel'); | ||
|
||
const fastifyInstrumentation = new FastifyInstrumentation(); | ||
fastifyInstrumentation.setTraceProvider(provider) | ||
|
||
module.exports = { fastifyInstrumentation } | ||
|
||
// ... in your Fastify definition | ||
const { fastifyInstrumentation } = require('./otel.js'); | ||
const Fastify = require('fastify'); | ||
|
||
const app = fastify(); | ||
// It is necessary to await for its register as it requires to be able | ||
// to intercept all route definitions | ||
await app.register(fastifyInstrumentation.plugin()); | ||
|
||
// automatically all your routes will be instrumented | ||
app.get('/', () => 'hello world') | ||
// as well as your instance level hooks. | ||
app.addHook('onError', () => /* do something */) | ||
|
||
// you can also scope your instrumentation to only be enabled on a sub context | ||
// of your application | ||
app.register((instance, opts, done) => { | ||
instance.register(fastifyInstrumentation.plugin()); | ||
// If only enabled in your encapsulated context | ||
// the parent context won't be instrumented | ||
app.get('/', () => 'hello world') | ||
|
||
}, { prefix: '/nested' }) | ||
``` | ||
|
||
> **Notes**: | ||
> | ||
> - This instrumentation requires `@opentelemetry/http-instrumentation` to be able to propagate the traces all the way back to upstream | ||
> - The HTTP instrumentation might cover all your routes although `@fastify/otel` just covers a subset of your application | ||
|
||
## License | ||
|
||
Licensed under [MIT](./LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict' | ||
|
||
module.exports = require('neostandard')({ | ||
ignores: require('neostandard').resolveIgnoresFromGitignore(), | ||
ts: true | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/// <reference types="node" /> | ||
|
||
import { InstrumentationBase, InstrumentationConfig, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation' | ||
import { FastifyInstance } from 'fastify' | ||
|
||
export interface FastifyOtelOptions {} | ||
export interface FastifyOtelInstrumentationOpts extends InstrumentationConfig {} | ||
|
||
declare class FastifyOtelInstrumentation<Config extends FastifyOtelInstrumentationOpts = FastifyOtelInstrumentationOpts> extends InstrumentationBase<Config> { | ||
static FastifyInstrumentation: FastifyOtelInstrumentation | ||
constructor (config?: FastifyOtelInstrumentationOpts) | ||
init (): InstrumentationNodeModuleDefinition[] | ||
plugin (): (instance: FastifyInstance, opts: FastifyOtelOptions, done: (err?: Error) => void) => void | ||
} | ||
|
||
export default FastifyOtelInstrumentation | ||
export { FastifyOtelInstrumentation } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, there's no need to perpetuate these badge things on new repos. For the most part, they were designed to show CI statuses. We use GHA, so such statuses are directly integrated into the repo already (the branch will have a green or red thing with a direct link to the results).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM, I mostly took this directly from
fastify-plugin
to keep some sort of standard across theREADME
; agree with you, I'll remove them away