Skip to content

Commit 65df1ae

Browse files
fix: http span attributes for endpoint detection documented (#249)
* docs: http span attributes for endpoint detection documented * fix: more accurate error log message * docs: http endpoint filtering regular expression escape and added example regexes
1 parent 94bde57 commit 65df1ae

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ This setting is independent from `LUMIGO_DEBUG`, that is, `LUMIGO_DEBUG` does no
110110
* `LUMIGO_SECRET_MASKING_REGEX_HTTP_RESPONSE_BODIES` applies secret redaction to HTTP response bodies
111111
* `LUMIGO_SECRET_MASKING_REGEX_HTTP_RESPONSE_HEADERS` applies secret redaction to HTTP response bodies
112112
* `LUMIGO_SECRET_MASKING_REGEX_ENVIRONMENT` applies secret redaction to process environment variables (that is, the content of `process.env`)
113-
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX='["regex1", "regex2"]'`: This option enables the filtering of client and server endpoints that match the supplied regular expressions. More fine-grained settings can be applied via the following environment variables, which will work in addition to `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX` for a specific span type:
114-
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_SERVER` applies the filter to server spans only. Matching is performed against the following attributes on a span: `url.path`, and `http.target`.
115-
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_CLIENT` applies the filter to client spans only. Matching is performed against the following attributes on a span: `url.full`, and `http.url`.
113+
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX='["regex1", "regex2"]'`: This option enables the filtering of client and server endpoints through regular expression searches. Fine-tune your settings via the following environment variables, which work in conjunction with `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX` for a specific span type:
114+
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_SERVER` applies the regular expression search exclusively to server spans. Searching is performed against the following attributes on a span: `url.path` and `http.target`.
115+
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_CLIENT` applies the regular expression search exclusively to client spans. Searching is performed against the following attributes on a span: `url.full` and `http.url`.
116116

117117
For more information check out [Filtering http endpoints](#filtering-http-endpoints).
118118

@@ -468,18 +468,30 @@ The possible variations are (case-insensitive):
468468
469469
### Filtering http endpoints
470470
471-
It is possible to filter out spans based on the HTTP server / client endpoints for all supported web server frameworks.
471+
You can selectively filter spans based on HTTP server/client endpoints for various components, not limited to web frameworks.
472472
473-
Set the `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX` environment variable to a list of regex strings that will match
474-
server / client endpoints.
475-
Spans with matching endpoints will be not be traced.
476-
If you only want to filter out server (inbound) spans or client (outbound) spans, you can set the env vars
477-
`LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_SERVER` or `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_CLIENT` respectively.
473+
#### Global filtering
474+
Set the `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX` environment variable to a list of regex strings. Spans with matching server/client endpoints will not be traced.
478475
479-
If we are filtering out an HTTP call to an opentelemetry traced component, every subsequent invocation made by that
476+
#### Specific Filtering
477+
For exclusive server (inbound) or client (outbound) span filtering, use the environment variables:
478+
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_SERVER`
479+
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_CLIENT`
480+
481+
Notes:
482+
* the environment variable must be a valid JSON array of strings, so if you want to match endpoint with the hostname `google.com` the environment variable value should be `["google\\.com"]`.
483+
* If we are filtering out an HTTP call to an opentelemetry traced component, every subsequent invocation made by that
480484
component won't be traced either.
481485
482-
When filtering out an HTTP span, all child spans will not be recorded as well.
486+
Examples:
487+
* Filtering out every incoming HTTP request to the `/login` endpoint (will also match requests such as `/login?user=foo`, `/login/bar`))):
488+
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_SERVER=["\\/login"]`
489+
* Filtering out every outgoing HTTP request to the `google.com` domain (will also match requests such as `google.com/foo`, `bar.google.com`):
490+
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_CLIENT=["google\\.com"]`'
491+
* Filtering out every outgoing HTTP request to `https://www.google.com` (will also match requests such as `https://www.google.com/`, `https://www.google.com/foo`)
492+
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_CLIENT=["https:\\/\\/www\\.google\\.com"]`
493+
* Filtering out every HTTP request (incoming or outgoing) with the word `login`:
494+
* `LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX=["login"]`
483495

484496
## Contributing
485497

src/samplers/lumigoSampler.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ export class LumigoSampler implements Sampler {
4646
}
4747

4848
export const extractEndpoint = (attributes: Attributes, spanKind: SpanKind): string | null => {
49+
/*
50+
* expected attributes for HTTP CLIENT spans:
51+
* url.full - The Absolute URL describing a network resource. E.g. "https://www.foo.bar/search?q=OpenTelemetry#SemConv"
52+
*
53+
* expected attributes for HTTP SERVER spans:
54+
* url.path - The URI path component. E.g. "/search"
55+
*
56+
* deprecated attributes (see https://opentelemetry.io/docs/specs/semconv/attributes-registry/http/#deprecated-http-attributes):
57+
* http.target - replaced by the url.path & url.query attributes. Example: "/search?q=OpenTelemetry#SemConv"
58+
* http.url - replaced by the url.full attribute. Example: "https://www.foo.bar/search?q=OpenTelemetry#SemConv"
59+
* */
4960
if (spanKind === SpanKind.CLIENT) {
5061
const endpoint_attr = attributes['url.full'] || attributes['http.url'];
5162
return endpoint_attr ? endpoint_attr.toString() : null;
@@ -111,7 +122,7 @@ export const parseStringToArray = (rawArray: string): string[] => {
111122
/* eslint-disable no-empty */
112123
} catch (err) {}
113124

114-
console.error(`Invalid array of strings format: '${rawArray}'`);
125+
console.error(`Not valid JSON format for an array of strings: '${rawArray}'`);
115126
return [];
116127
};
117128

0 commit comments

Comments
 (0)