Skip to content

Commit

Permalink
Disable managed identity for now
Browse files Browse the repository at this point in the history
  • Loading branch information
andychase committed Sep 23, 2024
1 parent c5c4af2 commit 9b98534
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 59 deletions.
4 changes: 4 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ OPENAI_API_KEY=YOUR_KEY
# Google
GOOGLE_API_KEY=YOUR_API_KEY
GOOGLE_CSE_ID=YOUR_ENGINE_ID



AZURE_USE_MANAGED_IDENTITY=false
20 changes: 10 additions & 10 deletions instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as Sentry from '@sentry/nextjs';
// import * as Sentry from '@sentry/nextjs';

export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./sentry.server.config');
}
// export async function register() {
// if (process.env.NEXT_RUNTIME === 'nodejs') {
// await import('./sentry.server.config');
// }

if (process.env.NEXT_RUNTIME === 'edge') {
await import('./sentry.edge.config');
}
}
// if (process.env.NEXT_RUNTIME === 'edge') {
// await import('./sentry.edge.config');
// }
// }

export const onRequestError = Sentry.captureRequestError;
// export const onRequestError = Sentry.captureRequestError;
90 changes: 45 additions & 45 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,48 @@ module.exports = nextConfig;

// Injected content via Sentry wizard below

const { withSentryConfig } = require("@sentry/nextjs");

module.exports = withSentryConfig(
module.exports,
{
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options

org: "andy-chase-l3",
project: "chatbotui-nextjs",
sentryUrl: "https://sentry.io/",

// Only print logs for uploading source maps in CI
silent: !process.env.CI,

// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,

// Automatically annotate React components to show their full name in breadcrumbs and session replay
reactComponentAnnotation: {
enabled: true,
},

// Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
// This can increase your server load as well as your hosting bill.
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// side errors will fail.
// tunnelRoute: "/monitoring",

// Hides source maps from generated client bundles
hideSourceMaps: true,

// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,

// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
// See the following for more information:
// https://docs.sentry.io/product/crons/
// https://vercel.com/docs/cron-jobs
automaticVercelMonitors: true,
}
);
// const { withSentryConfig } = require("@sentry/nextjs");

// module.exports = withSentryConfig(
// module.exports,
// {
// // For all available options, see:
// // https://github.com/getsentry/sentry-webpack-plugin#options

// org: "andy-chase-l3",
// project: "chatbotui-nextjs",
// sentryUrl: "https://sentry.io/",

// // Only print logs for uploading source maps in CI
// silent: !process.env.CI,

// // For all available options, see:
// // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

// // Upload a larger set of source maps for prettier stack traces (increases build time)
// widenClientFileUpload: true,

// // Automatically annotate React components to show their full name in breadcrumbs and session replay
// reactComponentAnnotation: {
// enabled: true,
// },

// // Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
// // This can increase your server load as well as your hosting bill.
// // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// // side errors will fail.
// // tunnelRoute: "/monitoring",

// // Hides source maps from generated client bundles
// hideSourceMaps: true,

// // Automatically tree-shake Sentry logger statements to reduce bundle size
// disableLogger: true,

// // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
// // See the following for more information:
// // https://docs.sentry.io/product/crons/
// // https://vercel.com/docs/cron-jobs
// automaticVercelMonitors: true,
// }
// );
2 changes: 1 addition & 1 deletion pages/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const handler = async (req: Request): Promise<Response> => {
...(OPENAI_API_TYPE === 'openai' && {
Authorization: `Bearer ${key ? key : process.env.OPENAI_API_KEY}`
}),
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY=="false" && {
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY!="true" && {
'api-key': `${key ? key : process.env.OPENAI_API_KEY}`
}),
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY=="true" && {
Expand Down
12 changes: 10 additions & 2 deletions utils/lib/azure.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
// lib/azure.js

import { DefaultAzureCredential } from "@azure/identity";
//import { DefaultAzureCredential } from "@azure/identity";
//import { log } from "console";
//import { getCache, setCache } from "./cache";



export async function getAuthToken() {
if (process.env.AZURE_USE_MANAGED_IDENTITY != "true") {
return "";
}
let cachedToken = process.env.AUTH_TOKEN ? JSON.parse(process.env.AUTH_TOKEN) : '';
if (!cachedToken || cachedToken.expiresOnTimestamp < Date.now()) {
let cachedCredential = new DefaultAzureCredential();
cachedToken = await cachedCredential.getToken("https://cognitiveservices.azure.com/.default");
//setCache("cachedToken", JSON.stringify(cachedToken));
//console.log("set the cachedToken in cache");
//let a = JSON.parse(getCache("cachedToken"));
//console.log("cachedToken from memory", a);
process.env.AUTH_TOKEN = JSON.stringify(cachedToken);
return cachedToken;
}
// console.log("cachedToken from memory", cachedToken);
console.log("cachedToken from memory", cachedToken);
return process.env.AUTH_TOKEN ? JSON.parse(process.env.AUTH_TOKEN) : '';;
}

2 changes: 1 addition & 1 deletion utils/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const OpenAIStream = async (
...(OPENAI_API_TYPE === 'openai' && {
Authorization: `Bearer ${key ? key : process.env.OPENAI_API_KEY}`
}),
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY=="false" && {
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY!="true" && {
'api-key': `${key ? key : process.env.OPENAI_API_KEY}`
}),
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY=="true" && {
Expand Down

0 comments on commit 9b98534

Please sign in to comment.