Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bring back browser extension #1152

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2b2b62a
feat: bring back browser extension
svrnm Sep 5, 2022
1328baa
fix: lint errors with browser extension
svrnm Sep 6, 2022
8898778
fix: reset version of browser extension, add browser extension to rel…
svrnm Sep 6, 2022
41d96bf
Merge branch 'main' into bring-back-browser-extension
svrnm Sep 15, 2022
be3d49b
fix: resolve merge conflict
svrnm Sep 16, 2022
720786a
Merge branch 'open-telemetry:main' into bring-back-browser-extension
svrnm Sep 19, 2022
65da98f
Merge branch 'main' into bring-back-browser-extension
vmarchaud Sep 19, 2022
ed7f4b1
fix: update release please manifest
svrnm Sep 27, 2022
9c40889
Merge branch 'main' into bring-back-browser-extension
svrnm Sep 27, 2022
4cab851
fix: resolve merge conflict
svrnm Oct 7, 2022
004ebc3
Merge branch 'main' into bring-back-browser-extension
svrnm Oct 10, 2022
b89606e
Merge branch 'main' into bring-back-browser-extension
svrnm Oct 19, 2022
9aa97b1
fix: merge current release please manifest
svrnm Nov 9, 2022
82e0392
fix: bring back archived package.json to solve merge conflict (will b…
svrnm Nov 9, 2022
71787a2
Merge branch 'main' into bring-back-browser-extension
svrnm Nov 9, 2022
c64cbcd
fix: remove archived package.json
svrnm Nov 9, 2022
04dceec
Merge branch 'main' into bring-back-browser-extension
svrnm Nov 9, 2022
a0351e5
fix: update package.json
svrnm May 3, 2023
6118091
Merge branch 'main' into bring-back-browser-extension
svrnm May 3, 2023
bc73fc1
fix merge conflict and merge main
svrnm Jun 11, 2024
8006737
update component owners and release-please-config
svrnm Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ components:
packages/baggage-span-processor:
- mikegoldsmith
- jamiedanielson
packages/opentelemetry-browser-extension-autoinjection:
- svrnm
packages/opentelemetry-host-metrics:
- legendecas
packages/opentelemetry-id-generator-aws-xray:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# OpenTelemetry Browser Extension

## :warning: ARCHIVED PROJECT

> This project has been archived by the maintainers on August 3 2022 because it was causing a failure in the CI and does not have any maintainer.
> Anyone who would like to maintain this project should open a PR to move it back into the lerna project and add themselves to the component owners file.

This browser extension allows you to inject [OpenTelemetry](https://opentelemetry.io/) instrumentation in any web page. It uses the [Web SDK](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-web) and can export data to Zipkin or an OpenTelemetry Collector.

Compatible with OpenTelemetry JS API and SDK `1.0+`.
Expand Down Expand Up @@ -50,6 +45,16 @@ Click on `Save & Reload`, check the developer toolbar to see how spans being are

![This image shows spans being printed into the console of the developer toolbar for opentelemetry.io](./images/console.png)

### Usage with OTLP

If you'd like to export your telemetry to an OTLP endpoint (i.e. [collector](https://github.com/open-telemetry/opentelemetry-collector)) you might run into issues
with [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/) (CSP) and [Cross-Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) (CORS).

To work around CSP you need another browser extension, that allows you to disable CSP for your targeted website.

To work around CORS you need your OTLP endpoint to provide you with the right headers. To help you with that you find a `docker-compose.yml` in [./server] that
starts a nginx, OTel collector and jaeger instance for you. You can leverage that example to get your own installation up and running.

## Known Limitations

1. The extension works with [active tab](https://developer.chrome.com/docs/extensions/mv3/manifest/activeTab/) permission, this means that every time you want to use it, you have to click the extension icon at least once for your tab.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@
"react-dom": "17.0.2"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/opentelemetry-browser-extension-autoinjection#readme"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
server {
listen 80 default_server;
server_name _;
location / {
# Take care of preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Max-Age' 1728000;
add_header "Access-Control-Allow-Origin" "$http_origin" always;
add_header 'Access-Control-Allow-Headers' 'Accept,Accept-Language,Content-Language,Content-Type,X-Requested-With' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}

add_header "Access-Control-Allow-Origin" "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Accept-Language,Content-Language,Content-Type,X-Requested-With' always;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://collector:4318;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "2"
services:
jaeger:
image: jaegertracing/all-in-one:latest
environment:
- COLLECTOR_OTLP_ENABLED=true
ports:
- "16686:16686"
proxy:
image: nginx:latest
ports:
- "4318:80"
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- collector
collector:
image: otel/opentelemetry-collector:latest
command: ["--config=/etc/otel-collector-config.yaml"]
volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
depends_on:
- jaeger
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
receivers:
otlp:
protocols:
http:
include_metadata: true
processors:
resource:
attributes:
- key: browser.user_agent
from_context: User-Agent
action: upsert
attributes:
actions:
- key: http.client_ip
from_context: X-Forwarded-For
action: upsert

exporters:
otlp:
endpoint: jaeger:4317
tls:
insecure: true
insecure_skip_verify: true
logging:

service:
pipelines:
traces:
receivers: [otlp]
processors: [resource,attributes]
exporters: [logging, otlp]
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-document-load';
import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
import { UserInteractionInstrumentation } from '@opentelemetry/instrumentation-user-interaction';
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import {
BatchSpanProcessor,
ConsoleSpanExporter,
Expand All @@ -37,45 +38,64 @@ export class WebInstrumentation {
withZoneContextManager: boolean;
provider: WebTracerProvider;
exporters: Exporters;
logger: Console;
instrumentations: {
[InstrumentationType.DOCUMENT_LOAD]: { enabled: boolean };
[InstrumentationType.FETCH]: { enabled: boolean };
[InstrumentationType.XML_HTTP_REQUEST]: { enabled: boolean };
[InstrumentationType.USER_INTERACTION]: { enabled: boolean };
};
constructor(
config: InstrumentationConfiguration,
provider: WebTracerProvider
provider: WebTracerProvider,
logger: Console
) {
this.exporters = config.exporters;
this.instrumentations = config.instrumentations;
this.provider = provider;
this.withZoneContextManager = config.withZoneContextManager;
this.logger = logger;
}

addExporters() {
if (this.exporters[ExporterType.CONSOLE].enabled) {
this.logger.info(
'[otel-extension] Logging spans to the console with ConsoleSpanExporter'
);
this.provider.addSpanProcessor(
new SimpleSpanProcessor(new ConsoleSpanExporter())
);
}

if (this.exporters[ExporterType.ZIPKIN].enabled) {
this.provider.addSpanProcessor(
new BatchSpanProcessor(
new ZipkinExporter({
const options = this.exporters[ExporterType.ZIPKIN].url
? {
url: this.exporters[ExporterType.ZIPKIN].url,
})
)
}
: {};
this.logger.info(
'[otel-extension] Logging spans to the console with ZipkinExporter(',
options,
')'
);
this.provider.addSpanProcessor(
new BatchSpanProcessor(new ZipkinExporter(options))
);
}

if (this.exporters[ExporterType.COLLECTOR_TRACE].enabled) {
if (this.exporters[ExporterType.TRACE_OTLP_HTTP].enabled) {
const options = this.exporters[ExporterType.TRACE_OTLP_HTTP].url
? {
url: this.exporters[ExporterType.TRACE_OTLP_HTTP].url,
}
: {};
this.logger.info(
'[otel-extension] Logging spans to the console with OTLPHttpTraceExporter(',
options,
')'
);
this.provider.addSpanProcessor(
new BatchSpanProcessor(
new OTLPTraceExporter({
url: this.exporters[ExporterType.COLLECTOR_TRACE].url,
})
)
new BatchSpanProcessor(new OTLPHttpTraceExporter(options))
);
}
}
Expand All @@ -95,6 +115,10 @@ export class WebInstrumentation {
instrumentations.push(new XMLHttpRequestInstrumentation());
}

if (this.instrumentations[InstrumentationType.USER_INTERACTION].enabled) {
instrumentations.push(new UserInteractionInstrumentation());
}

registerInstrumentations({
instrumentations,
tracerProvider: this.provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ new WebInstrumentation(
[InstrumentationType.XML_HTTP_REQUEST]: {
enabled: true,
},
[InstrumentationType.USER_INTERACTION]: {
enabled: true,
},
},
withZoneContextManager: true,
},
new WebTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: window.location.hostname,
}),
})
}),
console
).register();
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
"open_in_tab": true,
},
"web_accessible_resources": [
"instrumentation.js"
"instrumentation.js",
"instrumentation.js.map",
"contentScript.js.map",
"js/index.js.map"
],
"host_permissions": [
'<all_urls>'
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface Exporters {
enabled: boolean;
url: string;
};
[ExporterType.COLLECTOR_TRACE]: {
[ExporterType.TRACE_OTLP_HTTP]: {
enabled: boolean;
url: string;
};
Expand All @@ -43,6 +43,9 @@ export interface InstrumentationConfiguration {
[InstrumentationType.XML_HTTP_REQUEST]: {
enabled: boolean;
};
[InstrumentationType.USER_INTERACTION]: {
enabled: boolean;
};
};
withZoneContextManager: boolean;
}
Expand Down Expand Up @@ -81,7 +84,7 @@ export interface ExporterOptionProps {
isEnabled: boolean;
onToggle: (exporter: ExporterType) => void;
onValueChange?: (
name: ExporterType.ZIPKIN | ExporterType.COLLECTOR_TRACE,
name: ExporterType.ZIPKIN | ExporterType.TRACE_OTLP_HTTP,
newValue: string
) => void;
exporterPackageUrl: string;
Expand Down Expand Up @@ -117,13 +120,14 @@ export enum AppType {
export enum ExporterType {
CONSOLE = 'Console',
ZIPKIN = 'Zipkin',
COLLECTOR_TRACE = 'CollectorTrace',
TRACE_OTLP_HTTP = 'OTLP HTTP',
}

export enum InstrumentationType {
DOCUMENT_LOAD = 'DocumentLoad',
FETCH = 'Fetch',
XML_HTTP_REQUEST = 'XMLHttpRequest',
USER_INTERACTION = 'UserInteraction',
}

export enum DomElements {
Expand All @@ -136,7 +140,7 @@ export enum DomAttributes {

export enum PlaceholderValues {
ZIPKIN_URL = 'http://localhost:9411/api/v2/spans',
COLLECTOR_TRACE_URL = 'http://localhost:4318/v1/trace',
TRACE_OTLP_HTTP_URL = 'http://localhost:4318/v1/traces',
}

export enum Labels {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class App extends React.Component<AppProps, AppState> {
}

handleUrlChange(
name: ExporterType.ZIPKIN | ExporterType.COLLECTOR_TRACE,
name: ExporterType.ZIPKIN | ExporterType.TRACE_OTLP_HTTP,
value: string
) {
this.setState(state => {
Expand Down Expand Up @@ -244,13 +244,13 @@ export class App extends React.Component<AppProps, AppState> {
value={exporters[ExporterType.ZIPKIN].url}
/>
<ExporterOption
for={ExporterType.COLLECTOR_TRACE}
isEnabled={exporters[ExporterType.COLLECTOR_TRACE].enabled}
for={ExporterType.TRACE_OTLP_HTTP}
isEnabled={exporters[ExporterType.TRACE_OTLP_HTTP].enabled}
onToggle={this.toggleExporter}
onValueChange={this.handleUrlChange}
placeholderValue={PlaceholderValues.COLLECTOR_TRACE_URL}
exporterPackageUrl="https://www.npmjs.com/package/@opentelemetry/exporter-otlp-http"
value={exporters[ExporterType.COLLECTOR_TRACE].url}
placeholderValue={PlaceholderValues.TRACE_OTLP_HTTP_URL}
exporterPackageUrl="https://www.npmjs.com/package/@opentelemetry/exporter-trace-otlp-http"
value={exporters[ExporterType.TRACE_OTLP_HTTP].url}
/>
</Grid>
</Paper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ExporterOption extends React.Component<ExporterOptionProps> {
</FormHelperText>
</FormGroup>
</Grid>
{this.props.value !== undefined ? (
{this.props.value !== undefined && this.props.isEnabled ? (
<Grid item xs={12} md={9}>
<TextField
label={`${this.props.for} URL`}
Expand All @@ -67,7 +67,7 @@ export class ExporterOption extends React.Component<ExporterOptionProps> {
? this.props.onValueChange(
this.props.for as
| ExporterType.ZIPKIN
| ExporterType.COLLECTOR_TRACE,
| ExporterType.TRACE_OTLP_HTTP,
event.target.value
)
: () => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function loadFromStorage(): Promise<Storage> {
enabled: false,
url: '',
},
[ExporterType.COLLECTOR_TRACE]: {
[ExporterType.TRACE_OTLP_HTTP]: {
enabled: false,
url: '',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ describe('WebInstrumentation', () => {
enabled: true,
url: PlaceholderValues.ZIPKIN_URL,
},
[ExporterType.COLLECTOR_TRACE]: {
[ExporterType.TRACE_OTLP_HTTP]: {
enabled: true,
url: PlaceholderValues.COLLECTOR_TRACE_URL,
url: PlaceholderValues.TRACE_OTLP_HTTP_URL,
},
},
instrumentations: {
Expand All @@ -77,10 +77,15 @@ describe('WebInstrumentation', () => {
[InstrumentationType.XML_HTTP_REQUEST]: {
enabled: true,
},
[InstrumentationType.USER_INTERACTION]: {
// disabled, throws "ReferenceError: history is not defined"
enabled: false,
},
},
withZoneContextManager: true,
},
provider
provider,
console
);
instrumentation.register();
assert.ok(addSpanProcessorSpy.callCount === 3);
Expand Down
Loading
Loading