Skip to content

Commit

Permalink
moved appinsights to plugin (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhaufe authored Jul 30, 2024
1 parent d5ffa8b commit 0af55fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
16 changes: 16 additions & 0 deletions plugins/appInsights.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import appInsights from 'applicationinsights';

export default defineNuxtPlugin(nuxtApp => {
// https://learn.microsoft.com/en-us/azure/azure-monitor/app/nodejs#telemetryclient-api
appInsights.setup(process.env.APPINSIGHTS_CONNECTIONSTRING)
.setAutoCollectRequests(true)
.setAutoCollectPerformance(true, true)
.setAutoCollectExceptions(true)
.setAutoCollectDependencies(true)
.setAutoCollectConsole(true, true)
.setAutoCollectPreAggregatedMetrics(true)
.setSendLiveMetrics(false)
.setInternalLogging(false, true)
.enableWebInstrumentation(false)
.start();
})
15 changes: 12 additions & 3 deletions server/api/slack-bot/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { z } from "zod"
import crypto from 'crypto'
import { WebClient } from "@slack/web-api"
import fs from 'fs';
import appInsights from 'applicationinsights';

const ai = appInsights.defaultClient

const bodySchema = z.object({
type: z.string(),
Expand Down Expand Up @@ -92,8 +94,15 @@ export default defineEventHandler(async (event) => {
message: JSON.stringify(body.error.errors)
})

fs.appendFileSync('/log/slackbot.log', `SlackBotMessage Headers: ${JSON.stringify(headers)}\n`);
fs.appendFileSync('/slack-bot/slackbot.log', `SlackBotMessage rawBody: ${rawBody}\n`);

ai.trackTrace({
message: `SlackBotMessage Headers: ${JSON.stringify(headers)}`
})
ai.trackTrace({
message: `SlackBotMessage rawBody: ${rawBody}`
})

ai.flush()

if (!isValidSlackRequest(headers, rawBody))
throw createError({
Expand Down
16 changes: 0 additions & 16 deletions server/appInsights.ts

This file was deleted.

0 comments on commit 0af55fe

Please sign in to comment.