Skip to content

Commit

Permalink
fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
domasx2 committed Jun 2, 2022
1 parent abfe1c4 commit 161682f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions demo/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TracingInstrumentation } from '@grafana/agent-tracing-web';
import { ConsoleInstrumentation, initializeAgent, getWebInstrumentations } from '@grafana/agent-web';
import { initializeAgent, getWebInstrumentations } from '@grafana/agent-web';

const agent = initializeAgent({
url: 'http://localhost:12345/collect',
apiKey: 'secret',
instrumentations: [...getWebInstrumentations(), new TracingInstrumentation(), new ConsoleInstrumentation()],
instrumentations: [...getWebInstrumentations(), new TracingInstrumentation()],
app: {
name: 'frontend',
version: '1.0.0',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { defaultGlobalObjectKey } from './const';

export type { Config } from './types';
export type { Config, Patterns } from './types';
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export { initializeAgent } from './initialize';

export type { Agent } from './types';

export type { Config } from './config';
export type { Config, Patterns } from './config';
export { defaultGlobalObjectKey } from './config';

export type { Instrumentation } from './instrumentations';
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing-web/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ export class TracingInstrumentation extends BaseInstrumentation {
}

private getIgnoreUrls(): Array<string | RegExp> {
return this.agent.transports.value.flatMap((transport) => transport.getIgnoreUrls());
return this.agent.transports.transports.flatMap((transport) => transport.getIgnoreUrls());
}
}
28 changes: 22 additions & 6 deletions packages/web/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
Config,
defaultGlobalObjectKey,
Transport,
Patterns,
} from '@grafana/agent-core';

import { ErrorsInstrumentation, WebVitalsInstrumentation } from './instrumentations';
import { ConsoleInstrumentation, ErrorsInstrumentation, WebVitalsInstrumentation } from './instrumentations';
import { browserMeta, pageMeta } from './metas';
import { FetchTransport } from './transports';

Expand All @@ -24,14 +25,28 @@ export interface BrowserConfig {
metas?: MetaItem[];
instrumentations?: Instrumentation[];
transports?: Transport[];
ignoreErrors?: Patterns;
}

export const defaultMetas: MetaItem[] = [browserMeta, pageMeta];

export const getDefaultInstrumentations = (): Instrumentation[] => [
new ErrorsInstrumentation(),
new WebVitalsInstrumentation(),
];
interface GetWebInstrumentationsOptions {
captureConsole?: boolean
}

export const getWebInstrumentations = (options: GetWebInstrumentationsOptions = {}): Instrumentation[] => {

const instrumentations: Instrumentation[] = [
new ErrorsInstrumentation(),
new WebVitalsInstrumentation(),
];

if (options.captureConsole !== false) {
instrumentations.push(new ConsoleInstrumentation())
}

return instrumentations;
}

export function makeCoreConfig(browserConfig: BrowserConfig): Config {
const transports: Transport[] = [];
Expand All @@ -56,10 +71,11 @@ export function makeCoreConfig(browserConfig: BrowserConfig): Config {
preventGlobalExposure: browserConfig.preventGlobalExposure || false,
transports,
metas: browserConfig.metas ?? defaultMetas,
instrumentations: browserConfig.instrumentations ?? getDefaultInstrumentations(),
instrumentations: browserConfig.instrumentations ?? getWebInstrumentations(),
app: browserConfig.app,
session: browserConfig.session,
user: browserConfig.user,
ignoreErrors: browserConfig.ignoreErrors
};

return config;
Expand Down

0 comments on commit 161682f

Please sign in to comment.