Skip to content

Commit 7a853a3

Browse files
committed
feat: update dependencies and improve logging and storage configurations
- Updated the version of `@ai-sdk/google` from `^2.0.52` to `^3.0.6` in `package.json` and `package-lock.json`. - Added `cross-env` as a dependency in `package.json` to manage environment variables in scripts. - Modified the `dev:mastra` and `dev:next` scripts in `package.json` to use `cross-env` for setting `NODE_OPTIONS`. - Enhanced the logger configuration in `logger.ts` by removing OpenTelemetry tracing logic and simplifying log data structure. - Updated `pg-storage.ts` to use `ModelRouterEmbeddingModel` instead of `google.textEmbedding` for embedding generation. - Refactored `ChunkingService.ts` and `EmbeddingService.ts` to utilize `ModelRouterEmbeddingModel` for embedding tasks. - Removed unnecessary tracing logic from `generateEmbeddings` function in `pg-storage.ts`. - Updated statistics in `SDK_CRAWLER_STATISTICS_0.json` and `SDK_SESSION_POOL_STATE.json` to reflect new values and session details. - Deleted unused request queue file `jBMmaaywUPlwSK3.json`. - Improved documentation in `AGENTS.md` regarding observability imports and usage. - Refactored various service files to ensure consistent usage of embedding models and logging practices.
1 parent abe7289 commit 7a853a3

15 files changed

Lines changed: 219 additions & 174 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,9 @@ openapi.json
140140
.github/actions/**/.vercel_build_output/
141141
.github/actions/**/vercel.json
142142
nul
143+
src/mastra/public/storage/key_value_stores/default/*.json
144+
src/mastra/public/storage/key_value_stores/default/SDK_SESSION_POOL_STATE.json
145+
src/mastra/public/storage/request_queues/default/*.json
146+
src/mastra/public/storage/request_queues/default/rv4EFYzT2n22Qkr.json
147+
src/mastra/public/storage/key_value_stores/default/SDK_SESSION_POOL_STATE.json
148+
src/mastra/public/storage/key_value_stores/default/SDK_CRAWLER_STATISTICS_0.json

package-lock.json

Lines changed: 52 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"dev": "dotenvx run -- concurrently -n \"NEXT,MASTRA\" -c \"blue.bold,green.bold\" \"npm run dev:next\" \"npm run dev:mastra\"",
88
"build": "dotenvx run -- concurrently -n \"NEXT,MASTRA\" -c \"blue.bold,green.bold\" \"npm run build:next\" \"npm run build:mastra\"",
99
"start": "dotenvx run -- concurrently -n \"NEXT,MASTRA\" -c \"blue.bold,green.bold\" \"npm run start:next\" \"npm run start:mastra\"",
10-
"dev:mastra": "mastra dev",
11-
"dev:next": "next dev --turbopack",
10+
"dev:mastra": "cross-env NODE_OPTIONS='--max-old-space-size=8192' mastra dev",
11+
"dev:next": "cross-env NODE_OPTIONS='--max-old-space-size=8192' next dev --turbopack",
1212
"build:next": "next build",
1313
"build:mastra": "mastra build",
1414
"start:mastra": "mastra start",
@@ -42,7 +42,7 @@
4242
"node": ">=20.9.0"
4343
},
4444
"dependencies": {
45-
"@ai-sdk/google": "^2.0.52",
45+
"@ai-sdk/google": "^3.0.6",
4646
"@ai-sdk/google-vertex": "^4.0.11",
4747
"@ai-sdk/openai": "^3.0.7",
4848
"@ai-sdk/openai-compatible": "^2.0.4",
@@ -228,6 +228,7 @@
228228
"@typescript-eslint/eslint-plugin": "^8.52.0",
229229
"@typescript-eslint/parser": "^8.52.0",
230230
"@vitest/coverage-v8": "^4.0.16",
231+
"cross-env": "^10.1.0",
231232
"eslint": "^9.39.2",
232233
"eslint-config-prettier": "^10.1.8",
233234
"eslint-plugin-react-hooks": "^7.0.1",

src/mastra/config/logger.ts

Lines changed: 10 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { PinoLogger } from "@mastra/loggers";
2-
import { FileTransport } from "@mastra/loggers/file";
32
import * as fs from 'node:fs'
43
import * as path from 'node:path'
5-
import { trace, propagation, context as otelContext } from '@opentelemetry/api'
4+
// Logger intentionally contains no tracing logic. Observability exporters/bridges handle traces separately.
65

76
// Use __dirname directly for CommonJS
87
//const __dirname: string = path.resolve(path.dirname(''));
@@ -12,40 +11,8 @@ const logsDir: string = path.join(process.cwd(), 'data', 'logs')
1211
if (!fs.existsSync(logsDir)) {
1312
fs.mkdirSync(logsDir, { recursive: true })
1413
}
14+
// Enhanced PinoLogger
1515

16-
// OpenTelemetry helpers to enrich logs with trace context and Baggage
17-
const getActiveSpanContextInfo = () => {
18-
const span = trace.getActiveSpan()
19-
if (!span) {
20-
return { traceId: undefined, spanId: undefined }
21-
}
22-
const sc = (span as any).spanContext ? (span as any).spanContext() : undefined
23-
return { traceId: sc?.traceId, spanId: sc?.spanId }
24-
}
25-
26-
const BaggageToObject = (b: unknown) => {
27-
if (b === null || b === undefined) {
28-
return {}
29-
}
30-
const obj: Record<string, string> = {}
31-
for (const [k, v] of (b as any).getAllEntries()) {
32-
obj[k] = String(v.value)
33-
}
34-
return obj
35-
}
36-
37-
const attachTraceAndBaggage = (data: Record<string, unknown> = {}) => {
38-
try {
39-
const traceInfo = getActiveSpanContextInfo()
40-
const bag = propagation.getBaggage(otelContext.active())
41-
return { ...data, _trace: traceInfo, _Baggage: BaggageToObject(bag) }
42-
} catch {
43-
// Don't throw from logging helpers
44-
return data
45-
}
46-
}
47-
48-
// Enhanced PinoLogger with full tracing integration
4916
export const log = new PinoLogger({
5017
name: 'MastraLogger',
5118
level: 'debug',
@@ -87,18 +54,15 @@ export const logWorkflowStart = (
8754
input: Record<string, unknown>
8855
) => {
8956
const message = `🚀 Starting workflow: ${workflowId}`
90-
let data: {
57+
const data: {
9158
workflowId: string
9259
input: Record<string, unknown>
9360
timestamp: string
94-
_trace?: Record<string, unknown>
95-
_Baggage?: Record<string, string>
9661
} = {
9762
workflowId,
9863
input,
9964
timestamp: new Date().toISOString(),
10065
}
101-
data = attachTraceAndBaggage(data) as typeof data
10266
log.info(message, data)
10367
logToFile(message, data)
10468
}
@@ -109,20 +73,17 @@ export const logWorkflowEnd = (
10973
duration: number
11074
) => {
11175
const message = `✅ Workflow completed: ${workflowId}`
112-
let data: {
76+
const data: {
11377
workflowId: string
11478
output: Record<string, unknown>
11579
duration: string
11680
timestamp: string
117-
_trace?: Record<string, unknown>
118-
_Baggage?: Record<string, string>
11981
} = {
12082
workflowId,
12183
output,
12284
duration: `${duration}ms`,
12385
timestamp: new Date().toISOString(),
12486
}
125-
data = attachTraceAndBaggage(data) as typeof data
12687
log.info(message, data)
12788
logToFile(message, data)
12889
}
@@ -132,18 +93,15 @@ export const logStepStart = (
13293
input: Record<string, unknown>
13394
) => {
13495
const message = `📋 Starting step: ${stepId}`
135-
let data: {
96+
const data: {
13697
stepId: string
13798
input: Record<string, unknown>
13899
timestamp: string
139-
_trace?: Record<string, unknown>
140-
_Baggage?: Record<string, string>
141100
} = {
142101
stepId,
143102
input,
144103
timestamp: new Date().toISOString(),
145104
}
146-
data = attachTraceAndBaggage(data) as typeof data
147105
log.info(message, data)
148106
logToFile(message, data)
149107
}
@@ -154,20 +112,17 @@ export const logStepEnd = (
154112
duration: number
155113
) => {
156114
const message = `✓ Step completed: ${stepId}`
157-
let data: {
115+
const data: {
158116
stepId: string
159117
output: Record<string, unknown>
160118
duration: string
161119
timestamp: string
162-
_trace?: Record<string, unknown>
163-
_Baggage?: Record<string, string>
164120
} = {
165121
stepId,
166122
output,
167123
duration: `${duration}ms`,
168124
timestamp: new Date().toISOString(),
169125
}
170-
data = attachTraceAndBaggage(data) as typeof data
171126
log.info(message, data)
172127
logToFile(message, data)
173128
}
@@ -178,20 +133,17 @@ export const logToolExecution = (
178133
output?: Record<string, unknown>
179134
) => {
180135
const message = `🔧 Tool execution: ${toolId}`
181-
let data: {
136+
const data: {
182137
toolId: string
183138
input: Record<string, unknown>
184139
output?: Record<string, unknown>
185140
timestamp: string
186-
_trace?: Record<string, unknown>
187-
_Baggage?: Record<string, string>
188141
} = {
189142
toolId,
190143
input,
191144
output,
192145
timestamp: new Date().toISOString(),
193146
}
194-
data = attachTraceAndBaggage(data) as typeof data
195147
log.info(message, data)
196148
logToFile(message, data)
197149
}
@@ -202,20 +154,17 @@ export const logAgentActivity = (
202154
details: Record<string, unknown>
203155
) => {
204156
const message = `🤖 Agent activity: ${agentId} - ${action}`
205-
let data: {
157+
const data: {
206158
agentId: string
207159
action: string
208160
details: Record<string, unknown>
209161
timestamp: string
210-
_trace?: Record<string, unknown>
211-
_Baggage?: Record<string, string>
212162
} = {
213163
agentId,
214164
action,
215165
details,
216166
timestamp: new Date().toISOString(),
217167
}
218-
data = attachTraceAndBaggage(data) as typeof data
219168
log.info(message, data)
220169
logToFile(message, data)
221170
}
@@ -226,22 +175,19 @@ export const logError = (
226175
context?: Record<string, unknown>
227176
) => {
228177
const message = `❌ Error in ${component}`
229-
let data: {
178+
const data: {
230179
component: string
231180
error: string
232181
stack?: string
233182
context?: Record<string, unknown>
234183
timestamp: string
235-
_trace?: Record<string, unknown>
236-
_Baggage?: Record<string, string>
237184
} = {
238185
component,
239186
error: error instanceof Error ? error.message : String(error),
240187
stack: error instanceof Error ? error.stack : undefined,
241188
context,
242189
timestamp: new Date().toISOString(),
243190
}
244-
data = attachTraceAndBaggage(data) as typeof data
245191
log.error(message, data)
246192
logToFile(message, data)
247193
}
@@ -252,22 +198,19 @@ export const logProgress = (
252198
total: number
253199
) => {
254200
const logMessage = `📊 Progress: ${message} (${progress}/${total})`
255-
let data: {
201+
const data: {
256202
message: string
257203
progress: number
258204
total: number
259205
percentage: number
260206
timestamp: string
261-
_trace?: Record<string, unknown>
262-
_Baggage?: Record<string, string>
263207
} = {
264208
message,
265209
progress,
266210
total,
267211
percentage: Math.round((progress / total) * 100),
268212
timestamp: new Date().toISOString(),
269213
}
270-
data = attachTraceAndBaggage(data) as typeof data
271214
log.info(logMessage, data)
272215
logToFile(logMessage, data)
273216
}

0 commit comments

Comments
 (0)