forked from traceloop/jest-opentelemetry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
334 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
--- | ||
title: "What if I don't have OpenTelemetry installed?" | ||
--- | ||
|
||
No worries! You can install it in any existing Kubernetes environment in under 5 minutes by running the following set of commands. | ||
**No code changes are needed**. | ||
|
||
Feel free to contact us at dev@traceloop.dev if you need any help. | ||
|
||
<Accordion title="Other options"> | ||
[Odigo](https://docs.odigos.io/intro) is a new open source project that can do this for you without a single line of code. | ||
|
||
You can also find more information on [OpenTelemetry documentation](https://opentelemetry.io/docs/js/getting-started/). | ||
|
||
</Accordion> | ||
|
||
1. Install cert-manager. This is required for the OpenTelemetry operator to work. | ||
|
||
```bash | ||
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.11.0/cert-manager.yaml | ||
``` | ||
|
||
2. Install the [OpenTelemetry operator](https://opentelemetry.io/docs/k8s-operator/) so that metrics will be generated and collected automatically. | ||
|
||
```bash | ||
kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml | ||
``` | ||
|
||
3. Create a config file named `otel-collector.yaml` for your OpenTelemetry configurations: | ||
|
||
```yaml | ||
apiVersion: opentelemetry.io/v1alpha1 | ||
kind: Instrumentation | ||
metadata: | ||
name: otel-instrumentation | ||
spec: | ||
nodejs: | ||
image: traceloop/instrument-opentelemetry:node-0.3.0 | ||
exporter: | ||
endpoint: http://otel-collector:4317 | ||
propagators: | ||
- tracecontext | ||
- baggage | ||
- b3 | ||
|
||
--- | ||
apiVersion: opentelemetry.io/v1alpha1 | ||
kind: OpenTelemetryCollector | ||
metadata: | ||
name: otel | ||
spec: | ||
config: | | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
http: | ||
processors: | ||
batch: | ||
timeout: 100ms | ||
exporters: | ||
otlphttp: | ||
endpoint: http://host.docker.internal:4123 | ||
service: | ||
pipelines: | ||
traces: | ||
receivers: [otlp] | ||
processors: [batch] | ||
exporters: [otlphttp] | ||
``` | ||
<Accordion title="What are we doing here?"> | ||
We configure 2 separate things: | ||
1. The Instrumentation, which is an init-container which will run on any pod you explictly mark (see step 5). | ||
We are using our own init-container to get more data about your application (like the body of HTTP requests). | ||
You can always remove these lines to use the standard open telemetry init-container: | ||
```yaml | ||
nodejs: | ||
image: traceloop/instrument-opentelemetry:node-0.3.0 | ||
``` | ||
2. The OpenTelemetry collector, which will collect the metrics from the init-container and send them to the test runner. | ||
What's amazing here is that you can add other exporters to this config file to send the metrics to other services like Datadog and others. | ||
</Accordion> | ||
4. Apply the config file: | ||
```bash | ||
kubectl apply -f otel-collector.yaml | ||
``` | ||
|
||
5. Update any service you want to instrument with the following annotations (Change the 2 occurances of `my-service` to the name of your service): | ||
|
||
<Note> | ||
We add an env var named `SERVICE_NAME` to your service so that you can | ||
later identify it in the tests. | ||
</Note> | ||
|
||
```yaml | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: my-service | ||
spec: | ||
replicas: 1 | ||
template: | ||
annotations: | ||
instrumentation.opentelemetry.io/inject-nodejs: 'true' | ||
spec: | ||
containers: | ||
env: | ||
- name: SERVICE_NAME | ||
value: 'my-service' | ||
``` | ||
This will automatically instrument your service with OpenTelemetry and send the metrics to the OpenTelemetry collector. | ||
Apply those changes and you're done! You can start writing end to end tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: 'PostgreSQL' | ||
--- | ||
|
||
Each assrtion should start with defining the service that's sending requests to the Database you want to check. You do this by: | ||
|
||
```js | ||
expectTrace(traceloop.serviceByName('service-name'))... | ||
``` | ||
|
||
These are the options you can use for service selection: | ||
|
||
- `serviceByName` - the name of the service as reported in the `service.name` attribute | ||
(automatically reported by [Traceloop's init container](/jest-otel/no-otel)) | ||
- `serviceByK8sPodName` - the name of the pod as reported by Kubernetes | ||
- `serviceByCustomAttribute` - any custom attribute reported by your service to OpenTelemetry | ||
|
||
Following that, you can use any of the following assertions: | ||
|
||
- `toQueryPostgreSQL` | ||
|
||
Then, you can specifically assert for each of the properties of the request: | ||
|
||
- `withDatabaseName` | ||
|
||
So, a complete assertion can look like: | ||
|
||
```js | ||
expectTrace(traceloop.serviceByName('orders-service')) | ||
.toQueryPostgreSQL() | ||
.withDatabaseName('postgres'); | ||
``` |
Empty file.
Oops, something went wrong.