Compare commits
4 Commits
337842370b
...
0d9cb3f448
Author | SHA1 | Date |
---|---|---|
|
0d9cb3f448 | |
|
20d3fd1fe5 | |
|
414f0a6c95 | |
|
f962d29eda |
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@hono/oauth-providers': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Optionally pass state as an option to oauth provider
|
|
@ -12,10 +12,11 @@ export function discordAuth(options: {
|
||||||
client_id?: string
|
client_id?: string
|
||||||
client_secret?: string
|
client_secret?: string
|
||||||
redirect_uri?: string
|
redirect_uri?: string
|
||||||
|
state?: string
|
||||||
}): MiddlewareHandler {
|
}): MiddlewareHandler {
|
||||||
return async (c, next) => {
|
return async (c, next) => {
|
||||||
// Generate encoded "keys"
|
// Generate encoded "keys"
|
||||||
const newState = getRandomState()
|
const newState = options.state || getRandomState()
|
||||||
|
|
||||||
// Create new Auth instance
|
// Create new Auth instance
|
||||||
const auth = new AuthFlow({
|
const auth = new AuthFlow({
|
||||||
|
|
|
@ -13,9 +13,10 @@ export function facebookAuth(options: {
|
||||||
client_id?: string
|
client_id?: string
|
||||||
client_secret?: string
|
client_secret?: string
|
||||||
redirect_uri?: string
|
redirect_uri?: string
|
||||||
|
state?: string
|
||||||
}): MiddlewareHandler {
|
}): MiddlewareHandler {
|
||||||
return async (c, next) => {
|
return async (c, next) => {
|
||||||
const newState = getRandomState()
|
const newState = options.state || getRandomState()
|
||||||
// Create new Auth instance
|
// Create new Auth instance
|
||||||
const auth = new AuthFlow({
|
const auth = new AuthFlow({
|
||||||
client_id: options.client_id || (env(c).FACEBOOK_ID as string),
|
client_id: options.client_id || (env(c).FACEBOOK_ID as string),
|
||||||
|
|
|
@ -13,9 +13,10 @@ export function githubAuth(options: {
|
||||||
scope?: GitHubScope[]
|
scope?: GitHubScope[]
|
||||||
oauthApp?: boolean
|
oauthApp?: boolean
|
||||||
redirect_uri?: string
|
redirect_uri?: string
|
||||||
|
state?: string
|
||||||
}): MiddlewareHandler {
|
}): MiddlewareHandler {
|
||||||
return async (c, next) => {
|
return async (c, next) => {
|
||||||
const newState = getRandomState()
|
const newState = options.state || getRandomState()
|
||||||
// Create new Auth instance
|
// Create new Auth instance
|
||||||
const auth = new AuthFlow({
|
const auth = new AuthFlow({
|
||||||
client_id: options.client_id || (env(c).GITHUB_ID as string),
|
client_id: options.client_id || (env(c).GITHUB_ID as string),
|
||||||
|
|
|
@ -13,9 +13,10 @@ export function linkedinAuth(options: {
|
||||||
scope?: LinkedInScope[]
|
scope?: LinkedInScope[]
|
||||||
appAuth?: boolean
|
appAuth?: boolean
|
||||||
redirect_uri?: string
|
redirect_uri?: string
|
||||||
|
state?: string
|
||||||
}): MiddlewareHandler {
|
}): MiddlewareHandler {
|
||||||
return async (c, next) => {
|
return async (c, next) => {
|
||||||
const newState = getRandomState()
|
const newState = options.state || getRandomState()
|
||||||
// Create new Auth instance
|
// Create new Auth instance
|
||||||
const auth = new AuthFlow({
|
const auth = new AuthFlow({
|
||||||
client_id: options.client_id || (env(c).LINKEDIN_ID as string),
|
client_id: options.client_id || (env(c).LINKEDIN_ID as string),
|
||||||
|
|
|
@ -14,10 +14,11 @@ export function xAuth(options: {
|
||||||
client_id?: string
|
client_id?: string
|
||||||
client_secret?: string
|
client_secret?: string
|
||||||
redirect_uri?: string
|
redirect_uri?: string
|
||||||
|
state?: string
|
||||||
}): MiddlewareHandler {
|
}): MiddlewareHandler {
|
||||||
return async (c, next) => {
|
return async (c, next) => {
|
||||||
// Generate encoded "keys"
|
// Generate encoded "keys"
|
||||||
const newState = getRandomState()
|
const newState = options.state || getRandomState()
|
||||||
const challenge = await getCodeChallenge()
|
const challenge = await getCodeChallenge()
|
||||||
|
|
||||||
const auth = new AuthFlow({
|
const auth = new AuthFlow({
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
# @hono/otel
|
# @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
|
## 0.1.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@hono/otel",
|
"name": "@hono/otel",
|
||||||
"version": "0.1.1",
|
"version": "0.2.0",
|
||||||
"description": "OpenTelemetry middleware for Hono",
|
"description": "OpenTelemetry middleware for Hono",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"module": "dist/index.js",
|
"module": "dist/index.js",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { TracerProvider } from '@opentelemetry/api'
|
import type { TracerProvider } from '@opentelemetry/api'
|
||||||
import { SpanKind, SpanStatusCode, trace } from '@opentelemetry/api'
|
import { SpanKind, SpanStatusCode, trace, context, propagation } from '@opentelemetry/api'
|
||||||
import {
|
import {
|
||||||
ATTR_HTTP_REQUEST_HEADER,
|
ATTR_HTTP_REQUEST_HEADER,
|
||||||
ATTR_HTTP_REQUEST_METHOD,
|
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 tracerProvider = options.tracerProvider ?? trace.getTracerProvider()
|
||||||
const tracer = tracerProvider.getTracer(PACKAGE_NAME, PACKAGE_VERSION)
|
const tracer = tracerProvider.getTracer(PACKAGE_NAME, PACKAGE_VERSION)
|
||||||
return createMiddleware<E, P, I>(async (c, next) => {
|
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
|
const routePath = c.req.routePath
|
||||||
await tracer.startActiveSpan(
|
await tracer.startActiveSpan(
|
||||||
`${c.req.method} ${c.req.routePath}`,
|
`${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,
|
[ATTR_HTTP_ROUTE]: routePath,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
activeContext,
|
||||||
async (span) => {
|
async (span) => {
|
||||||
for (const [name, value] of Object.entries(c.req.header())) {
|
for (const [name, value] of Object.entries(c.req.header())) {
|
||||||
span.setAttribute(ATTR_HTTP_REQUEST_HEADER(name), value)
|
span.setAttribute(ATTR_HTTP_REQUEST_HEADER(name), value)
|
||||||
|
|
Loading…
Reference in New Issue