Skip to content

Commit

Permalink
Improve OTEL trace and add missing information about storage calls (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored Dec 22, 2024
1 parent 25f1460 commit 15c1412
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { parse, print } from 'graphql';
import { Inject, Injectable, Scope } from 'graphql-modules';
import lodash from 'lodash';
import { z } from 'zod';
import { traceFn } from '@hive/service-common';
import type {
ConditionalBreakingChangeMetadata,
SchemaChangeType,
Expand Down Expand Up @@ -95,6 +96,15 @@ export class SchemaManager {
});
}

@traceFn('SchemaManager.compose', {
initAttributes: input => ({
'hive.target.id': input.targetId,
'hive.organization.id': input.organizationId,
'hive.project.id': input.projectId,
'input.only.composable': input.onlyComposable,
'input.services.count': input.services.length,
}),
})
async compose(
input: TargetSelector & {
onlyComposable: boolean;
Expand Down Expand Up @@ -187,6 +197,14 @@ export class SchemaManager {
throw new Error('Composition was successful but is missing a supergraph');
}

@traceFn('SchemaManager.getSchemasOfVersion', {
initAttributes: selector => ({
'hive.target.id': selector.targetId,
'hive.organization.id': selector.organizationId,
'hive.project.id': selector.projectId,
'hive.version.id': selector.versionId,
}),
})
@atomic(stringifySelector)
async getSchemasOfVersion(
selector: {
Expand All @@ -204,6 +222,14 @@ export class SchemaManager {
return schemas;
}

@traceFn('SchemaManager.getSchemasOfVersion', {
initAttributes: input => ({
'hive.target.id': input.targetId,
'hive.organization.id': input.organizationId,
'hive.project.id': input.projectId,
'hive.version.id': input.id,
}),
})
@atomic(stringifySelector)
async getMaybeSchemasOfVersion(schemaVersion: SchemaVersion) {
this.logger.debug('Fetching schemas (schemaVersionId=%s)', schemaVersion.id);
Expand Down Expand Up @@ -298,6 +324,15 @@ export class SchemaManager {
};
}

@traceFn('SchemaManager.updateSchemaVersionStatus', {
initAttributes: input => ({
'hive.target.id': input.targetId,
'hive.organization.id': input.organizationId,
'hive.project.id': input.projectId,
'hive.version.id': input.versionId,
'hive.input.valid': input.valid,
}),
})
async updateSchemaVersionStatus(
input: TargetSelector & { versionId: string; valid: boolean },
): Promise<SchemaVersion> {
Expand Down Expand Up @@ -337,6 +372,16 @@ export class SchemaManager {
});
}

@traceFn('SchemaManager.createVersion', {
initAttributes: input => ({
'hive.target.id': input.targetId,
'hive.organization.id': input.organizationId,
'hive.project.id': input.projectId,
'hive.version.commit': input.commit,
'hive.version.valid': input.valid,
'hive.version.service': input.service || '',
}),
})
async createVersion(
input: ({
commit: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { SchemaVersionMapper as SchemaVersion } from '../module.graphql.map
import { print } from 'graphql';
import { Injectable, Scope } from 'graphql-modules';
import { CriticalityLevel } from '@graphql-inspector/core';
import { traceFn } from '@hive/service-common';
import type { SchemaChangeType } from '@hive/storage';
import {
containsSupergraphSpec,
Expand Down Expand Up @@ -38,6 +39,14 @@ export class SchemaVersionHelper {
private logger: Logger,
) {}

@traceFn('SchemaVersionHelper.composeSchemaVersion', {
initAttributes: input => ({
'hive.target.id': input.targetId,
'hive.organization.id': input.organizationId,
'hive.project.id': input.projectId,
'hive.version.id': input.id,
}),
})
@cache<SchemaVersion>(version => version.id)
private async composeSchemaVersion(schemaVersion: SchemaVersion) {
const [schemas, project, organization] = await Promise.all([
Expand Down Expand Up @@ -145,6 +154,18 @@ export class SchemaVersionHelper {
return supergraphAst;
}

@traceFn('SchemaVersionHelper.getSchemaChanges', {
initAttributes: input => ({
'hive.target.id': input.targetId,
'hive.organization.id': input.organizationId,
'hive.project.id': input.projectId,
'hive.version.id': input.id,
}),
resultAttributes: changes => ({
'hive.breaking-changes.count': changes?.breaking?.length,
'hive.safe-changes.count': changes?.safe?.length,
}),
})
@cache<SchemaVersion>(version => version.id)
private async getSchemaChanges(schemaVersion: SchemaVersion) {
if (!schemaVersion.isComposable) {
Expand Down Expand Up @@ -282,6 +303,15 @@ export class SchemaVersionHelper {
return !composableVersion;
}

@traceFn('SchemaVersionHelper.getServiceSdlForPreviousVersionService', {
initAttributes: (schemaVersion, serviceName) => ({
'hive.organization.id': schemaVersion.organizationId,
'hive.project.id': schemaVersion.projectId,
'hive.target.id': schemaVersion.targetId,
'hive.version.id': schemaVersion.id,
'hive.service.name': serviceName,
}),
})
async getServiceSdlForPreviousVersionService(schemaVersion: SchemaVersion, serviceName: string) {
const previousVersion = await this.getPreviousDiffableSchemaVersion(schemaVersion);
if (!previousVersion) {
Expand Down

0 comments on commit 15c1412

Please sign in to comment.