Skip to content

Commit

Permalink
Fill the params for the events
Browse files Browse the repository at this point in the history
  • Loading branch information
chtushar committed Nov 16, 2023
1 parent 58b33d7 commit 2b4f03c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/OpenAPM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ const packageJson = getPackageJson();
export class OpenAPM extends LevitateEvents {
private path: string;
private metricsServerPort: number;
private environment: string;
readonly environment: string;
readonly program: string;
readonly levitateConfig?: LevitateConfig | undefined;
private defaultLabels?: Record<string, string>;
private requestsCounterConfig: CounterConfiguration<string>;
private requestDurationHistogramConfig: HistogramConfiguration<string>;
Expand All @@ -97,6 +99,7 @@ export class OpenAPM extends LevitateEvents {
this.path = options?.path ?? '/metrics';
this.metricsServerPort = options?.metricsServerPort ?? 9097;
this.environment = options?.environment ?? 'production';
this.program = packageJson?.name ?? '';
this.defaultLabels = options?.defaultLabels;
this.requestsCounterConfig = options?.requestsCounterConfig ?? {
name: 'http_requests_total',
Expand Down
16 changes: 8 additions & 8 deletions src/clients/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export const instrumentExpress = (
timestamp: new Date().toISOString(),
event_name: 'express_app',
event_state: 'start',
entity_type: '',
workspace: '',
namespace: '',
data_source_name: ''
entity_type: 'API',
workspace: openapm.program,
namespace: openapm.environment,
data_source_name: openapm.levitateConfig?.dataSourceName ?? ''
});
const server = original.apply(this, args) as Server;

Expand All @@ -57,10 +57,10 @@ export const instrumentExpress = (
timestamp: new Date().toISOString(),
event_name: 'express_app',
event_state: 'stop',
entity_type: '',
workspace: '',
namespace: '',
data_source_name: ''
entity_type: 'API',
workspace: openapm.program,
namespace: openapm.environment,
data_source_name: openapm.levitateConfig?.dataSourceName ?? ''
});
return original.apply(this, args);
};
Expand Down
22 changes: 12 additions & 10 deletions src/levitate/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import EventEmitter from 'events';
export interface LevitateConfig {
host?: string;
orgSlug: string;
dataSourceName: string;
refreshTokens: {
write: string;
};
Expand Down Expand Up @@ -71,11 +72,12 @@ export class LevitateEvents extends EventEmitter {

private initiateEventListeners() {
if (typeof this.levitateConfig?.refreshTokens?.write === 'string') {
this.once('application_started', this.applicationStarted);
this.once('application_started', this.putDomainEvents);
this.once('application_stopped', this.putDomainEvents);
}
}

private applicationStarted(body: DomainEventsBody) {
private putDomainEvents(body: DomainEventsBody) {
const params = new URLSearchParams();

if (!!body) {
Expand All @@ -85,14 +87,14 @@ export class LevitateEvents extends EventEmitter {
}
}

// fetch(this.eventsUrl.toString(), {
// method: 'PUT',
// headers: {
// 'Content-Type': 'application/json',
// 'X-LAST9-API-TOKEN': `Bearer `
// },
// body: params
// });
fetch(this.eventsUrl.toString(), {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'X-LAST9-API-TOKEN': `Bearer `
},
body: params
});
console.log(params);
}
}
Expand Down

0 comments on commit 2b4f03c

Please sign in to comment.