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

APM execution context - app, page, entitiy id #124996

Merged
merged 79 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
7deba6b
Client side execution app level context propagation
Feb 8, 2022
c44c4f2
context$ + apm rum integration
Feb 8, 2022
6b18395
invert the context parent \ child relationship (cc @mikhail)
Feb 8, 2022
a0044cd
Pass down context to apm on server
Feb 8, 2022
1115e93
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 8, 2022
ac41e1f
types
Feb 8, 2022
c2ed495
eslint
Feb 8, 2022
600607c
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 8, 2022
85408b1
parent <> child
Feb 8, 2022
efb7952
docs + eslint + jest
Feb 9, 2022
5da627a
execution context mock
Feb 9, 2022
1c1fce1
eslint
Feb 9, 2022
ed018ba
git pushMerge branch 'main' of https://github.com/elastic/kibana into…
Feb 9, 2022
5200052
jest
Feb 9, 2022
4c151dd
jest
Feb 9, 2022
b64e5e2
server jest
Feb 9, 2022
f1fc110
check
Feb 9, 2022
f413c38
jest
Feb 9, 2022
97350de
storybook
Feb 9, 2022
cf33228
jest
Feb 9, 2022
666441c
report the current space
Feb 10, 2022
d8c69c4
fix server side context container
Feb 10, 2022
6168b00
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 10, 2022
abcccdc
Remove spaces for now
Feb 10, 2022
824cb2a
docssss
Feb 10, 2022
89d7064
jest
Feb 10, 2022
e32f869
lint
Feb 10, 2022
a0c344e
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 10, 2022
756e7f5
test
Feb 11, 2022
aa6b774
Merge branch 'main' into client-side-execution-context
Feb 14, 2022
7cce534
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 14, 2022
ccb285d
Merge branch 'client-side-execution-context' of github.com:lizozom/ki…
Feb 14, 2022
8efe9ad
docs
Feb 15, 2022
7402fba
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 15, 2022
21e4438
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 15, 2022
c9fa18d
revert file
Feb 15, 2022
4b29f04
doc
Feb 15, 2022
b600cc0
all context params are optional
Feb 15, 2022
7cfd118
clear on page change
Feb 15, 2022
400731a
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 15, 2022
2a1a373
lint
Feb 15, 2022
2b45d23
ts
Feb 15, 2022
1cedb99
skipped test again
Feb 16, 2022
bb58dd2
testing fixes
Feb 16, 2022
2f2be65
oops
Feb 16, 2022
349ef2c
code review #1
Feb 17, 2022
47447e1
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 17, 2022
46807d3
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 21, 2022
efd5ea4
code review #2
Feb 21, 2022
80b1b68
getAsLabels
Feb 21, 2022
3c8a87d
maps inherit dashboard context
Feb 21, 2022
86b8cba
docs
Feb 21, 2022
66d6d3c
ts
Feb 21, 2022
7c500c7
Give common context to all vis editors
Feb 21, 2022
358515d
fix test
Feb 21, 2022
cb939d1
ts \ es \ tests
Feb 22, 2022
1dce721
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 22, 2022
84129cb
labels
Feb 22, 2022
984abf3
missing types
Feb 22, 2022
77decb1
docsy docs
Feb 22, 2022
2c0efd2
cr #3
Feb 22, 2022
19140f7
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 23, 2022
8a420c5
improve jest
Feb 23, 2022
5dad2dc
Use editor name
Feb 23, 2022
4facdf1
Update src/plugins/visualizations/public/visualize_app/components/vis…
lizozom Feb 23, 2022
585d690
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 24, 2022
f094803
fix maps context
Feb 24, 2022
59960cf
Merge branch 'client-side-execution-context' of github.com:lizozom/ki…
Feb 24, 2022
2a15a64
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 24, 2022
b0e216d
jest tests for maps
Feb 24, 2022
c10afe8
cr
Feb 24, 2022
d7c01e4
Merge branch 'main' of https://github.com/elastic/kibana into client-…
Feb 24, 2022
4a96dac
docs
Feb 24, 2022
a78a4b8
Update execution_context.test.ts
lizozom Feb 24, 2022
4dbc83e
docs
Feb 24, 2022
4c83f61
Merge branch 'client-side-execution-context' of github.com:lizozom/ki…
Feb 24, 2022
a57bed7
lint
Feb 27, 2022
7d8b955
Merge branch 'main' into client-side-execution-context
Feb 28, 2022
373eb31
Merge branch 'main' into client-side-execution-context
Mar 1, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [CoreSetup](./kibana-plugin-core-public.coresetup.md) &gt; [executionContext](./kibana-plugin-core-public.coresetup.executioncontext.md)

## CoreSetup.executionContext property

[ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md)

<b>Signature:</b>

```typescript
executionContext: ExecutionContextSetup;
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
| Property | Type | Description |
| --- | --- | --- |
| [application](./kibana-plugin-core-public.coresetup.application.md) | ApplicationSetup | [ApplicationSetup](./kibana-plugin-core-public.applicationsetup.md) |
| [executionContext](./kibana-plugin-core-public.coresetup.executioncontext.md) | ExecutionContextSetup | [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md) |
| [fatalErrors](./kibana-plugin-core-public.coresetup.fatalerrors.md) | FatalErrorsSetup | [FatalErrorsSetup](./kibana-plugin-core-public.fatalerrorssetup.md) |
| [getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md) | StartServicesAccessor&lt;TPluginsStart, TStart&gt; | [StartServicesAccessor](./kibana-plugin-core-public.startservicesaccessor.md) |
| [http](./kibana-plugin-core-public.coresetup.http.md) | HttpSetup | [HttpSetup](./kibana-plugin-core-public.httpsetup.md) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [CoreStart](./kibana-plugin-core-public.corestart.md) &gt; [executionContext](./kibana-plugin-core-public.corestart.executioncontext.md)

## CoreStart.executionContext property

[ExecutionContextStart](./kibana-plugin-core-public.executioncontextstart.md)

<b>Signature:</b>

```typescript
executionContext: ExecutionContextStart;
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface CoreStart
| [chrome](./kibana-plugin-core-public.corestart.chrome.md) | ChromeStart | [ChromeStart](./kibana-plugin-core-public.chromestart.md) |
| [deprecations](./kibana-plugin-core-public.corestart.deprecations.md) | DeprecationsServiceStart | [DeprecationsServiceStart](./kibana-plugin-core-public.deprecationsservicestart.md) |
| [docLinks](./kibana-plugin-core-public.corestart.doclinks.md) | DocLinksStart | [DocLinksStart](./kibana-plugin-core-public.doclinksstart.md) |
| [executionContext](./kibana-plugin-core-public.corestart.executioncontext.md) | ExecutionContextStart | [ExecutionContextStart](./kibana-plugin-core-public.executioncontextstart.md) |
| [fatalErrors](./kibana-plugin-core-public.corestart.fatalerrors.md) | FatalErrorsStart | [FatalErrorsStart](./kibana-plugin-core-public.fatalerrorsstart.md) |
| [http](./kibana-plugin-core-public.corestart.http.md) | HttpStart | [HttpStart](./kibana-plugin-core-public.httpstart.md) |
| [i18n](./kibana-plugin-core-public.corestart.i18n.md) | I18nStart | [I18nStart](./kibana-plugin-core-public.i18nstart.md) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md) &gt; [clear](./kibana-plugin-core-public.executioncontextsetup.clear.md)

## ExecutionContextSetup.clear() method

clears the context

<b>Signature:</b>

```typescript
clear(): void;
```
<b>Returns:</b>

void

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md) &gt; [context$](./kibana-plugin-core-public.executioncontextsetup.context_.md)

## ExecutionContextSetup.context$ property

The current context observable

<b>Signature:</b>

```typescript
context$: Observable<KibanaExecutionContext>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md) &gt; [get](./kibana-plugin-core-public.executioncontextsetup.get.md)

## ExecutionContextSetup.get() method

Get the current top level context

<b>Signature:</b>

```typescript
get(): KibanaExecutionContext;
```
<b>Returns:</b>

KibanaExecutionContext

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md) &gt; [getAsLabels](./kibana-plugin-core-public.executioncontextsetup.getaslabels.md)

## ExecutionContextSetup.getAsLabels() method

returns apm labels

<b>Signature:</b>

```typescript
getAsLabels(): Labels;
```
<b>Returns:</b>

Labels

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md)

## ExecutionContextSetup interface

Kibana execution context. Used to provide execution context to Elasticsearch, reporting, performance monitoring, etc.

<b>Signature:</b>

```typescript
export interface ExecutionContextSetup
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [context$](./kibana-plugin-core-public.executioncontextsetup.context_.md) | Observable&lt;KibanaExecutionContext&gt; | The current context observable |

## Methods

| Method | Description |
| --- | --- |
| [clear()](./kibana-plugin-core-public.executioncontextsetup.clear.md) | clears the context |
| [get()](./kibana-plugin-core-public.executioncontextsetup.get.md) | Get the current top level context |
| [getAsLabels()](./kibana-plugin-core-public.executioncontextsetup.getaslabels.md) | returns apm labels |
| [set(c$)](./kibana-plugin-core-public.executioncontextsetup.set.md) | Set the current top level context |
| [withGlobalContext(context)](./kibana-plugin-core-public.executioncontextsetup.withglobalcontext.md) | merges the current top level context with the specific event context |

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md) &gt; [set](./kibana-plugin-core-public.executioncontextsetup.set.md)

## ExecutionContextSetup.set() method

Set the current top level context

<b>Signature:</b>

```typescript
set(c$: KibanaExecutionContext): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| c$ | KibanaExecutionContext | |

<b>Returns:</b>

void

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md) &gt; [withGlobalContext](./kibana-plugin-core-public.executioncontextsetup.withglobalcontext.md)

## ExecutionContextSetup.withGlobalContext() method

merges the current top level context with the specific event context

<b>Signature:</b>

```typescript
withGlobalContext(context?: KibanaExecutionContext): KibanaExecutionContext;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| context | KibanaExecutionContext | |

<b>Returns:</b>

KibanaExecutionContext

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ExecutionContextStart](./kibana-plugin-core-public.executioncontextstart.md)

## ExecutionContextStart type

See [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md)<!-- -->.

<b>Signature:</b>

```typescript
export declare type ExecutionContextStart = ExecutionContextSetup;
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ Represents a meta-information about a Kibana entity initiating a search request.

```typescript
export declare type KibanaExecutionContext = {
readonly type: string;
readonly name: string;
readonly id: string;
readonly type?: string;
readonly name?: string;
readonly page?: string;
readonly id?: string;
readonly description?: string;
readonly url?: string;
child?: KibanaExecutionContext;
Expand Down
2 changes: 2 additions & 0 deletions docs/development/core/public/kibana-plugin-core-public.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [DeprecationsServiceStart](./kibana-plugin-core-public.deprecationsservicestart.md) | DeprecationsService provides methods to fetch domain deprecation details from the Kibana server. |
| [DocLinksStart](./kibana-plugin-core-public.doclinksstart.md) | |
| [ErrorToastOptions](./kibana-plugin-core-public.errortoastoptions.md) | Options available for [IToasts](./kibana-plugin-core-public.itoasts.md) error APIs. |
| [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md) | Kibana execution context. Used to provide execution context to Elasticsearch, reporting, performance monitoring, etc. |
| [FatalErrorInfo](./kibana-plugin-core-public.fatalerrorinfo.md) | Represents the <code>message</code> and <code>stack</code> of a fatal Error |
| [FatalErrorsSetup](./kibana-plugin-core-public.fatalerrorssetup.md) | FatalErrors stop the Kibana Public Core and displays a fatal error screen with details about the Kibana build and the error. |
| [HttpFetchOptions](./kibana-plugin-core-public.httpfetchoptions.md) | All options that may be used with a [HttpHandler](./kibana-plugin-core-public.httphandler.md)<!-- -->. |
Expand Down Expand Up @@ -160,6 +161,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [ChromeBreadcrumb](./kibana-plugin-core-public.chromebreadcrumb.md) | |
| [ChromeHelpExtensionLinkBase](./kibana-plugin-core-public.chromehelpextensionlinkbase.md) | |
| [ChromeHelpExtensionMenuLink](./kibana-plugin-core-public.chromehelpextensionmenulink.md) | |
| [ExecutionContextStart](./kibana-plugin-core-public.executioncontextstart.md) | See [ExecutionContextSetup](./kibana-plugin-core-public.executioncontextsetup.md)<!-- -->. |
| [FatalErrorsStart](./kibana-plugin-core-public.fatalerrorsstart.md) | FatalErrors stop the Kibana Public Core and displays a fatal error screen with details about the Kibana build and the error. |
| [HttpStart](./kibana-plugin-core-public.httpstart.md) | See [HttpSetup](./kibana-plugin-core-public.httpsetup.md) |
| [IToasts](./kibana-plugin-core-public.itoasts.md) | Methods for adding and removing global toast messages. See [ToastsApi](./kibana-plugin-core-public.toastsapi.md)<!-- -->. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [ExecutionContextSetup](./kibana-plugin-core-server.executioncontextsetup.md) &gt; [getAsLabels](./kibana-plugin-core-server.executioncontextsetup.getaslabels.md)

## ExecutionContextSetup.getAsLabels() method

<b>Signature:</b>

```typescript
getAsLabels(): apm.Labels;
```
<b>Returns:</b>

apm.Labels

Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export interface ExecutionContextSetup

| Method | Description |
| --- | --- |
| [getAsLabels()](./kibana-plugin-core-server.executioncontextsetup.getaslabels.md) | |
| [withContext(context, fn)](./kibana-plugin-core-server.executioncontextsetup.withcontext.md) | Keeps track of execution context while the passed function is executed. Data are carried over all async operations spawned by the passed function. The nested calls stack the registered context on top of each other. |

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ Represents a meta-information about a Kibana entity initiating a search request.

```typescript
export declare type KibanaExecutionContext = {
readonly type: string;
readonly name: string;
readonly id: string;
readonly type?: string;
readonly name?: string;
readonly page?: string;
readonly id?: string;
readonly description?: string;
readonly url?: string;
child?: KibanaExecutionContext;
Expand Down
4 changes: 4 additions & 0 deletions src/core/public/apm_system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { Transaction } from '@elastic/apm-rum';
import { ApmSystem } from './apm_system';
import { Subject } from 'rxjs';
import { InternalApplicationStart } from './application/types';
import { executionContextServiceMock } from './execution_context/execution_context_service.mock';

const initMock = init as jest.Mocked<typeof init>;
const apmMock = apm as DeeplyMockedKeys<typeof apm>;
Expand Down Expand Up @@ -96,6 +97,7 @@ describe('ApmSystem', () => {
application: {
currentAppId$,
} as any as InternalApplicationStart,
executionContext: executionContextServiceMock.createInternalStartContract(),
});

expect(mark).toHaveBeenCalledWith('apm-start');
Expand All @@ -118,6 +120,7 @@ describe('ApmSystem', () => {
application: {
currentAppId$,
} as any as InternalApplicationStart,
executionContext: executionContextServiceMock.createInternalStartContract(),
});
currentAppId$.next('myapp');

Expand Down Expand Up @@ -145,6 +148,7 @@ describe('ApmSystem', () => {
application: {
currentAppId$,
} as any as InternalApplicationStart,
executionContext: executionContextServiceMock.createInternalStartContract(),
});
currentAppId$.next('myapp');

Expand Down
12 changes: 12 additions & 0 deletions src/core/public/apm_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { ApmBase, AgentConfigOptions, Transaction } from '@elastic/apm-rum'
import { modifyUrl } from '@kbn/std';
import { CachedResourceObserver } from './apm_resource_counter';
import type { InternalApplicationStart } from './application';
import { ExecutionContextStart } from './execution_context';

/** "GET protocol://hostname:port/pathname" */
const HTTP_REQUEST_TRANSACTION_NAME_REGEX =
Expand All @@ -27,13 +28,15 @@ interface ApmConfig extends AgentConfigOptions {

interface StartDeps {
application: InternalApplicationStart;
executionContext: ExecutionContextStart;
}

export class ApmSystem {
private readonly enabled: boolean;
private pageLoadTransaction?: Transaction;
private resourceObserver: CachedResourceObserver;
private apm?: ApmBase;

/**
* `apmConfig` would be populated with relevant APM RUM agent
* configuration if server is started with elastic.apm.* config.
Expand Down Expand Up @@ -64,6 +67,15 @@ export class ApmSystem {

this.markPageLoadStart();

start.executionContext.context$.subscribe((c) => {
// We're using labels because we want the context to be indexed
// https://www.elastic.co/guide/en/apm/get-started/current/metadata.html
const apmContext = start.executionContext.getAsLabels();
this.apm?.addLabels(apmContext);
});

// TODO: Start a new transaction every page change instead of every app change.

/**
* Register listeners for navigation changes and capture them as
* route-change transactions after Kibana app is bootstrapped
Expand Down
Loading