Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2040c6f
moving APM types to apm-types pkg
cauemarcondes May 12, 2026
68c4d95
re-exporting
cauemarcondes May 12, 2026
7d660c8
ficing ci
cauemarcondes May 15, 2026
a527d26
Changes from node scripts/lint_ts_projects --fix
kibanamachine May 14, 2026
6478813
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine May 14, 2026
8624ac6
limits
cauemarcondes May 15, 2026
f70b61f
TO FIX: Run node 'scripts/yarn_deduplicate && yarn kbn bootstrap' loc…
kibanamachine May 15, 2026
2327957
Changes from node scripts/lint_ts_projects --fix
kibanamachine May 15, 2026
f9ad718
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine May 15, 2026
d41f7ab
event outcome
cauemarcondes May 15, 2026
e843995
fixing ebt
cauemarcondes May 19, 2026
0d0d1f1
addressing PR comments
cauemarcondes May 19, 2026
257735c
updating limits
cauemarcondes May 19, 2026
8b1b5f3
limits
cauemarcondes May 19, 2026
ec312c5
02 - Spacetime apm-common
cauemarcondes May 12, 2026
bb0c74e
moving stuff around
cauemarcondes May 12, 2026
f02615c
updating apm agent config exports
cauemarcondes May 12, 2026
54d5341
updating configs
cauemarcondes May 12, 2026
2c0c82a
fixing imports
cauemarcondes May 12, 2026
4a34f89
refactoring
cauemarcondes May 13, 2026
841a0fd
fixing export
cauemarcondes May 13, 2026
261e387
moving env definitions
cauemarcondes May 13, 2026
dfc0f63
moving stuff around
cauemarcondes May 12, 2026
11e3e48
refactoring
cauemarcondes May 13, 2026
4b1ed12
moving env definitions
cauemarcondes May 13, 2026
6818d92
apm-api-shared
cauemarcondes May 12, 2026
aadda4f
import fixes
cauemarcondes May 13, 2026
eaf1a7d
updating imports
cauemarcondes May 13, 2026
1de363c
updating license
cauemarcondes May 19, 2026
e422a0c
apm-common merging problem
cauemarcondes May 27, 2026
000eb83
fixing apm-common
cauemarcondes May 27, 2026
9681d5d
fixing merge problem
cauemarcondes May 27, 2026
5ef4927
reverting env
cauemarcondes May 27, 2026
b79e376
relocating
cauemarcondes May 27, 2026
5094b8a
Changes from node scripts/lint.js --fix
kibanamachine May 27, 2026
270190c
Changes from node scripts/lint_ts_projects --fix
kibanamachine May 27, 2026
6cebe24
Changes from node scripts/generate codeowners
kibanamachine May 27, 2026
9afaa37
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine May 27, 2026
c4120be
renaming package
cauemarcondes May 28, 2026
83ecc61
removing data_view route
cauemarcondes May 28, 2026
a67bbdf
removing diagnostics
cauemarcondes May 28, 2026
9ddc1cd
Changes from node scripts/lint.js --fix
kibanamachine May 28, 2026
e3f6514
Changes from node scripts/lint_ts_projects --fix
kibanamachine May 28, 2026
c80230b
Changes from node scripts/generate codeowners
kibanamachine May 28, 2026
96def99
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine May 28, 2026
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ x-pack/platform/packages/shared/kbn-ai-assistant @elastic/search-kibana @elastic
x-pack/platform/packages/shared/kbn-ai-tools @elastic/appex-ai-infra
x-pack/platform/packages/shared/kbn-ai-tools-cli @elastic/appex-ai-infra
x-pack/platform/packages/shared/kbn-alerting-comparators @elastic/response-ops
x-pack/platform/packages/shared/kbn-apm-api-shared @elastic/obs-presentation-team @elastic/obs-exploration-team
x-pack/platform/packages/shared/kbn-apm-common @elastic/obs-presentation-team @elastic/obs-exploration-team
x-pack/platform/packages/shared/kbn-apm-types @elastic/obs-presentation-team @elastic/obs-exploration-team
x-pack/platform/packages/shared/kbn-change-history @elastic/security-detection-rule-management
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
"@kbn/anonymization-common": "link:x-pack/platform/packages/shared/ai-infra/anonymization-common",
"@kbn/anonymization-plugin": "link:x-pack/platform/plugins/shared/anonymization",
"@kbn/anonymization-ui": "link:x-pack/platform/packages/shared/ai-infra/anonymization-ui",
"@kbn/apm-api-shared": "link:x-pack/platform/packages/shared/kbn-apm-api-shared",
"@kbn/apm-common": "link:x-pack/platform/packages/shared/kbn-apm-common",
"@kbn/apm-config-loader": "link:src/platform/packages/private/kbn-apm-config-loader",
"@kbn/apm-data-access-plugin": "link:x-pack/solutions/observability/plugins/apm_data_access",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
"@kbn/anonymization-ui/*": ["x-pack/platform/packages/shared/ai-infra/anonymization-ui/*"],
"@kbn/api-contracts": ["packages/kbn-api-contracts"],
"@kbn/api-contracts/*": ["packages/kbn-api-contracts/*"],
"@kbn/apm-api-shared": ["x-pack/platform/packages/shared/kbn-apm-api-shared"],
"@kbn/apm-api-shared/*": ["x-pack/platform/packages/shared/kbn-apm-api-shared/*"],
"@kbn/apm-common": ["x-pack/platform/packages/shared/kbn-apm-common"],
"@kbn/apm-common/*": ["x-pack/platform/packages/shared/kbn-apm-common/*"],
"@kbn/apm-config-loader": ["src/platform/packages/private/kbn-apm-config-loader"],
Expand Down
65 changes: 65 additions & 0 deletions x-pack/platform/packages/shared/kbn-apm-api-shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export {
createCallApmApiV2,
type APMClientV2,
type AutoAbortedAPMClientV2,
type APIReturnType,
} from './src/create_call_apm_api';
export { routeDefinitions } from './src/routes';
export type { SharedAPMRouteRepository } from './src/routes';
export type * from './src/routes/historical_data';
export type * from './src/routes/suggestions';
export type * from './src/routes/agent_keys';
export type * from './src/routes/traces';
export type * from './src/routes/span_links';
export type * from './src/routes/observability_overview';
export type * from './src/routes/agent_explorer';
export type * from './src/routes/alerts';
export type * from './src/routes/assistant_functions';
export type * from './src/routes/correlations';
export type * from './src/routes/custom_dashboards';
export type * from './src/routes/dependencies';
export type * from './src/routes/transactions';
export type * from './src/routes/services';
export type * from './src/routes/service_map';
export type * from './src/routes/errors';
export type * from './src/routes/infrastructure';
export type * from './src/routes/environments';
export type * from './src/routes/event_metadata';
export type * from './src/routes/fallback_to_transactions';
export type * from './src/routes/latency_distribution';
export type * from './src/routes/metrics';
export type * from './src/routes/profiling';
export type * from './src/routes/service_groups';
export type * from './src/routes/time_range_metadata';
export type * from './src/routes/custom_links';
export type * from './src/routes/anomaly_detection';
export type * from './src/routes/mobile';
export type * from './src/routes/mobile_errors';
export type * from './src/routes/mobile_crashes';
export type * from './src/routes/fleet';
export type * from './src/routes/debug_telemetry';
export type * from './src/routes/storage_explorer';
export type * from './src/routes/source_maps';
export type * from './src/routes/agent_configuration';
export { sourceMapRt } from './src/routes/source_maps';
export { filterOptionsRt, payloadRt } from './src/routes/custom_links';
export {
rangeRt,
kueryRt,
probabilityRt,
offsetRt,
serviceTransactionDataSourceRt,
transactionDataSourceRt,
filtersRt,
} from './src/default_api_types';
export {
OBSERVABILITY_APM_CPS_ENABLED_DEFAULT,
OBSERVABILITY_APM_CPS_ENABLED_FEATURE_FLAG,
} from './src/cps_feature_flag';
10 changes: 10 additions & 0 deletions x-pack/platform/packages/shared/kbn-apm-api-shared/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "shared-common",
"id": "@kbn/apm-api-shared",
"owner": [
"@elastic/obs-presentation-team",
"@elastic/obs-exploration-team"
],
"group": "platform",
"visibility": "shared"
}
46 changes: 46 additions & 0 deletions x-pack/platform/packages/shared/kbn-apm-api-shared/moon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This file is generated by the @kbn/moon package. Any manual edits will be erased!
# To extend this, write your extensions/overrides to 'moon.extend.yml'
# then regenerate this file with: 'node scripts/regenerate_moon_projects.js --update --filter @kbn/apm-api-shared'

$schema: https://moonrepo.dev/schemas/project.json
id: '@kbn/apm-api-shared'
layer: unknown
owners:
defaultOwner: '@elastic/obs-presentation-team'
toolchains:
default: node
language: typescript
project:
title: '@kbn/apm-api-shared'
description: Moon project for @kbn/apm-api-shared
channel: ''
owner: '@elastic/obs-presentation-team'
sourceRoot: x-pack/platform/packages/shared/kbn-apm-api-shared
dependsOn:
- '@kbn/server-route-repository-utils'
- '@kbn/apm-common'
- '@kbn/io-ts-utils'
- '@kbn/core'
- '@kbn/server-route-repository'
- '@kbn/cps-utils'
- '@kbn/es-query'
- '@kbn/apm-types'
- '@kbn/es-types'
- '@kbn/security-plugin-types-common'
- '@kbn/fleet-plugin'
- '@kbn/profiling-utils'
- '@kbn/slo-schema'
- '@kbn/elastic-agent-utils'
- '@kbn/apm-types-shared'
tags:
- shared-common
- package
- prod
- group-platform
- shared
fileGroups:
src:
- '**/*.ts'
- '**/*.tsx'
- '!target/**/*'
tasks: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/apm-api-shared",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0"
}
90 changes: 90 additions & 0 deletions x-pack/platform/packages/shared/kbn-apm-api-shared/src/call_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { CoreSetup, CoreStart } from '@kbn/core/public';
import { isString, startsWith } from 'lodash';
import { LRUCache as LRU } from 'lru-cache';
import hash from 'object-hash';
import type { FetchOptions } from './create_call_apm_api';

function fetchOptionsWithDebug(fetchOptions: FetchOptions, inspectableEsQueriesEnabled: boolean) {
const debugEnabled =
inspectableEsQueriesEnabled && startsWith(fetchOptions.pathname, '/internal/apm');

const { body, ...rest } = fetchOptions;

return {
...rest,
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
query: {
...fetchOptions.query,
...(debugEnabled ? { _inspect: true } : {}),
},
};
}

const cache = new LRU<string, any>({ max: 100, ttl: 1000 * 60 * 60 });

export function clearCache() {
cache.clear();
}

export type CallApi = typeof callApi;

export async function callApi<T = void>(
{ http, uiSettings }: CoreStart | CoreSetup,
fetchOptions: FetchOptions
): Promise<T> {
const inspectableEsQueriesEnabled: boolean =
// For now this needs to be hardcoded as we cannot import the key, as it lives inside the observability plugin,
// and refactoring it is outside the scope of this PR, but ideally this should be imported from the same place as the key is defined
uiSettings?.get('observability:enableInspectEsQueries') ?? false;
const cacheKey = getCacheKey(fetchOptions);
const cacheResponse = cache.get(cacheKey);
if (cacheResponse) {
return cacheResponse;
}

const {
pathname,
method = 'get',
...options
} = fetchOptionsWithDebug(fetchOptions, inspectableEsQueriesEnabled);

const lowercaseMethod = method.toLowerCase() as 'get' | 'post' | 'put' | 'delete' | 'patch';

const res = await http[lowercaseMethod]<T>(pathname, options);

if (isCachable(fetchOptions)) {
cache.set(cacheKey, res);
}

return res;
}

// only cache items that has a time range with `start` and `end` params,
// and where `end` is not a timestamp in the future
function isCachable(fetchOptions: FetchOptions) {
if (fetchOptions.isCachable !== undefined) {
return fetchOptions.isCachable;
}

if (!(fetchOptions.query && fetchOptions.query.start && fetchOptions.query.end)) {
return false;
}

return (
isString(fetchOptions.query.end) && new Date(fetchOptions.query.end).getTime() < Date.now()
);
}

// order the options object to make sure that two objects with the same arguments, produce produce the
// same cache key regardless of the order of properties
function getCacheKey(options: FetchOptions) {
const { pathname, method, body, query, headers } = options;
return hash({ pathname, method, body, query, headers });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

/** Use with `feature_flags.overrides` in kibana.yml to toggle CPS integration for APM. */
export const OBSERVABILITY_APM_CPS_ENABLED_FEATURE_FLAG = 'observability.apm.cpsEnabled' as const;

/**
* Fallback when the flag is unset and no override exists (same default as the removed
* `xpack.apm.featureFlags.apmCPSEnabled` setting).
*/
export const OBSERVABILITY_APM_CPS_ENABLED_DEFAULT = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { CoreStart } from '@kbn/core/public';
import type { EndpointOf, ReturnOf } from '@kbn/server-route-repository-utils';
import { formatRequest } from '@kbn/server-route-repository-utils';
import { type RouteRepositoryClient } from '@kbn/server-route-repository';
import type { HttpFetchOptions } from '@kbn/core/public';
import type { ICPSManager } from '@kbn/cps-utils';
import type { SharedAPMRouteRepository } from './routes';
import type { CallApi } from './call_api';
import { callApi } from './call_api';
import {
OBSERVABILITY_APM_CPS_ENABLED_DEFAULT,
OBSERVABILITY_APM_CPS_ENABLED_FEATURE_FLAG,
} from './cps_feature_flag';

export type FetchOptions = Omit<HttpFetchOptions, 'body'> & {
pathname: string;
isCachable?: boolean;
method?: string;
body?: any;
};

type APMClientOptions = Omit<FetchOptions, 'query' | 'body' | 'pathname' | 'signal'> & {
signal: AbortSignal | null;
};

export type APMClientV2 = RouteRepositoryClient<
SharedAPMRouteRepository,
APMClientOptions
>['fetch'];

export type AutoAbortedAPMClientV2 = RouteRepositoryClient<
SharedAPMRouteRepository,
Omit<APMClientOptions, 'signal'>
>['fetch'];

type APIEndpoint = EndpointOf<SharedAPMRouteRepository>;

export type APIReturnType<TEndpoint extends APIEndpoint> = ReturnOf<
SharedAPMRouteRepository,
TEndpoint
>;

interface Dependencies {
cpsManager?: ICPSManager;
}

export function createCallApmApiV2(
core: CoreStart,
{ cpsManager }: Dependencies = {}
): APMClientV2 {
return ((endpoint, options) => {
const { params } = options as unknown as {
params?: Partial<Record<string, any>>;
};

const { method, pathname, version } = formatRequest(endpoint, params?.path);
const isCpsEnabled = core.featureFlags.getBooleanValue(
OBSERVABILITY_APM_CPS_ENABLED_FEATURE_FLAG,
OBSERVABILITY_APM_CPS_ENABLED_DEFAULT
);
const projectRouting = isCpsEnabled ? cpsManager?.getProjectRouting() : undefined;

return callApi(core, {
...options,
method,
pathname,
body: params?.body,
query: params?.query,
version,
headers: {
...(options as any)?.headers,
...(projectRouting ? { 'x-project-routing': projectRouting } : {}),
},
} as unknown as Parameters<CallApi>[1]);
}) as APMClientV2;
}
Loading
Loading