Skip to content

Commit

Permalink
Ai event logging (#292)
Browse files Browse the repository at this point in the history
* feat: Add Application Insights logging for Slack bot messages

* added appInsights doc reference
  • Loading branch information
mlhaufe authored Jul 30, 2024
1 parent e73b1b2 commit 65ee15a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions server/api/slack-bot/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { z } from "zod"
import crypto from 'crypto'
import { WebClient } from "@slack/web-api"
import appInsights from '../../appInsights'

const ai = appInsights.defaultClient;

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

console.log('Slack event headers', JSON.stringify(headers))
console.log('Slack event body', rawBody)
ai.trackTrace({
message: 'SlackBotMessage Headers: ' + JSON.stringify(headers)
})
ai.trackTrace({
message: 'SlackBotMessage rawBody: ' + rawBody
})

if (!isValidSlackRequest(headers, rawBody))
throw createError({
Expand Down
5 changes: 4 additions & 1 deletion server/appInsights.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as appInsights from 'applicationinsights';

// https://learn.microsoft.com/en-us/azure/azure-monitor/app/nodejs#telemetryclient-api
appInsights.setup(process.env.APPINSIGHTS_INSTRUMENTATIONKEY)
.setAutoCollectRequests(true)
.setAutoCollectPerformance(true, true)
Expand All @@ -10,4 +11,6 @@ appInsights.setup(process.env.APPINSIGHTS_INSTRUMENTATIONKEY)
.setSendLiveMetrics(false)
.setInternalLogging(false, true)
.enableWebInstrumentation(false)
.start();
.start();

export default appInsights;

0 comments on commit 65ee15a

Please sign in to comment.