220
221
private _post(iKey: string, eventName: string, properties?: TelemetryProps, measurements?: TelemetryMeasurements, context?: { readonly endpointUrl: string | undefined; readonly trackingId: string | undefined }): void {
223
>
const commonProps = context
224
? { ...this._commonProps, copilot_trackingId: context.trackingId }
225
: this._commonProps;
227
>
ver: 1,
228
>
name: `Microsoft.ApplicationInsights.${iKey.replace(/-/g, '')}.Event`,
229
>
time: new Date().toISOString(),
230
>
sampleRate: 100,
231
>
seq: '',
232
>
iKey,
233
>
tags: { 'ai.operation.id': generateUuid() },
234
>
data: {
235
>
baseType: 'EventData',
236
>
baseData: {
237
>
name,
238
>
// `unique_id` is a fresh per-event id (its hydro column is read by the Copilot
239
>
// Telemetry Service from the snake_case `unique_id` property, NOT `uniqueId`),
240
>
// mirroring the Copilot extension so each emitted event stays individually
241
>
// addressable. Placed first so explicit properties still win on collision.
242
>
properties: context
243
? { unique_id: generateUuid(), ...commonProps, ...properties, copilot_trackingId: context.trackingId }
244
: { unique_id: generateUuid(), ...commonProps, ...properties },
246
>
},
247
>
},
248
>
};
249
>
250
>
this._logService.trace(`[ahp-restricted] emit ${name} (iKey ${iKey.slice(0, 8)})`);
251
>
252
>
if (typeof this._fetchFn !== 'function') {
253
this._logService.warn('[ahp-restricted] global fetch unavailable; telemetry not sent');
254
return;
255
}
257
>
// Fire-and-forget: post the event and move on. Delivery/robustness is intentionally kept
258
>
// simple here — failures are logged, not retried (a retry loop would only mask local
259
>
// telemetry-blocking resolvers, which do not exist in production).
260
>
this._fetchFn(context?.endpointUrl || (context ? GH_TELEMETRY_URL : this._endpointUrl), {
261
>
method: 'POST',
262
>
headers: { 'Content-Type': 'application/x-json-stream' },
263
>
body: JSON.stringify(envelope),
264
>
}).then(res => {
265
>
if (!res.ok) {
266
this._logService.warn(`[ahp-restricted] ${name} rejected: HTTP ${res.status}`);
267
}
269
this._logService.warn(`[ahp-restricted] ${name} POST failed: ${err instanceof Error ? err.message : String(err)}`);
271
>
}
272
}
273