Compare commits

...

4 Commits

Author SHA1 Message Date
ms 0d9cb3f448
Merge f962d29eda into 20d3fd1fe5 2025-05-11 11:05:35 -07:00
github-actions[bot] 20d3fd1fe5
Version Packages (#1152)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-05-08 08:10:40 +09:00
Nicholas Dobie 414f0a6c95
feat(otel): Added support for W3C Trace Context format (#1151)
* feat(otel): Added support for W3C Trace Context format

* removed unneeded HonoRequest
2025-05-08 07:20:02 +09:00
mani f962d29eda Pass optional state as parameter, so we can link other state info to it 2025-02-24 01:48:30 +02:00
9 changed files with 30 additions and 7 deletions

View File

@ -0,0 +1,5 @@
---
'@hono/oauth-providers': minor
---
Optionally pass state as an option to oauth provider

View File

@ -12,10 +12,11 @@ export function discordAuth(options: {
client_id?: string
client_secret?: string
redirect_uri?: string
state?: string
}): MiddlewareHandler {
return async (c, next) => {
// Generate encoded "keys"
const newState = getRandomState()
const newState = options.state || getRandomState()
// Create new Auth instance
const auth = new AuthFlow({

View File

@ -13,9 +13,10 @@ export function facebookAuth(options: {
client_id?: string
client_secret?: string
redirect_uri?: string
state?: string
}): MiddlewareHandler {
return async (c, next) => {
const newState = getRandomState()
const newState = options.state || getRandomState()
// Create new Auth instance
const auth = new AuthFlow({
client_id: options.client_id || (env(c).FACEBOOK_ID as string),

View File

@ -13,9 +13,10 @@ export function githubAuth(options: {
scope?: GitHubScope[]
oauthApp?: boolean
redirect_uri?: string
state?: string
}): MiddlewareHandler {
return async (c, next) => {
const newState = getRandomState()
const newState = options.state || getRandomState()
// Create new Auth instance
const auth = new AuthFlow({
client_id: options.client_id || (env(c).GITHUB_ID as string),

View File

@ -13,9 +13,10 @@ export function linkedinAuth(options: {
scope?: LinkedInScope[]
appAuth?: boolean
redirect_uri?: string
state?: string
}): MiddlewareHandler {
return async (c, next) => {
const newState = getRandomState()
const newState = options.state || getRandomState()
// Create new Auth instance
const auth = new AuthFlow({
client_id: options.client_id || (env(c).LINKEDIN_ID as string),

View File

@ -14,10 +14,11 @@ export function xAuth(options: {
client_id?: string
client_secret?: string
redirect_uri?: string
state?: string
}): MiddlewareHandler {
return async (c, next) => {
// Generate encoded "keys"
const newState = getRandomState()
const newState = options.state || getRandomState()
const challenge = await getCodeChallenge()
const auth = new AuthFlow({

View File

@ -1,5 +1,11 @@
# @hono/otel
## 0.2.0
### Minor Changes
- [#1151](https://github.com/honojs/middleware/pull/1151) [`414f0a6c9502de4135d50a4f80698a8d2f09a81d`](https://github.com/honojs/middleware/commit/414f0a6c9502de4135d50a4f80698a8d2f09a81d) Thanks [@nrdobie](https://github.com/nrdobie)! - Added support for W3C Trace Context format
## 0.1.1
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@hono/otel",
"version": "0.1.1",
"version": "0.2.0",
"description": "OpenTelemetry middleware for Hono",
"type": "module",
"module": "dist/index.js",

View File

@ -1,5 +1,5 @@
import type { TracerProvider } from '@opentelemetry/api'
import { SpanKind, SpanStatusCode, trace } from '@opentelemetry/api'
import { SpanKind, SpanStatusCode, trace, context, propagation } from '@opentelemetry/api'
import {
ATTR_HTTP_REQUEST_HEADER,
ATTR_HTTP_REQUEST_METHOD,
@ -42,6 +42,12 @@ export const otel = <E extends Env = any, P extends string = any, I extends Inpu
const tracerProvider = options.tracerProvider ?? trace.getTracerProvider()
const tracer = tracerProvider.getTracer(PACKAGE_NAME, PACKAGE_VERSION)
return createMiddleware<E, P, I>(async (c, next) => {
// Handle propagation of trace context from a request using the W3C Trace Context format
let activeContext = context.active()
if (c.req.header('traceparent')) {
activeContext = propagation.extract(context.active(), c.req.header())
}
const routePath = c.req.routePath
await tracer.startActiveSpan(
`${c.req.method} ${c.req.routePath}`,
@ -53,6 +59,7 @@ export const otel = <E extends Env = any, P extends string = any, I extends Inpu
[ATTR_HTTP_ROUTE]: routePath,
},
},
activeContext,
async (span) => {
for (const [name, value] of Object.entries(c.req.header())) {
span.setAttribute(ATTR_HTTP_REQUEST_HEADER(name), value)