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

OTLP telemetry exporter #213

Merged
merged 24 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
60 changes: 39 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@koa/cors": "^4.0.0",
"@koa/router": "^12.0.0",
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/exporter-logs-otlp-http": "0.41.2",
"@opentelemetry/exporter-trace-otlp-http": "^0.41.2",
"@opentelemetry/sdk-trace-base": "^1.15.2",
"@types/koa": "^2.13.8",
Expand Down
8 changes: 4 additions & 4 deletions src/cloud-cli/applications/configure.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import axios from "axios";
import fs from "fs";
import YAML from "yaml";
import { createGlobalLogger } from "../../telemetry/logs";
import { GlobalLogger } from "../../telemetry/logs";
import { getCloudCredentials } from "../utils";
import { ConfigFile, loadConfigFile, dbosConfigFilePath } from "../../dbos-runtime/config";

export async function configureApp(host: string, port: string, dbName: string) {
const logger = createGlobalLogger();
const logger = new GlobalLogger();
const userCredentials = getCloudCredentials();
const bearerToken = "Bearer " + userCredentials.token;

// call cloud and get hostname and port
const res = await axios.get(`http://${host}:${port}/${userCredentials.userName}/databases/userdb/info/${dbName}`,
const res = await axios.get(`http://${host}:${port}/${userCredentials.userName}/databases/userdb/info/${dbName}`,
{
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 2 additions & 2 deletions src/cloud-cli/applications/delete-app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import axios from "axios";
import { createGlobalLogger } from "../../telemetry/logs";
import { GlobalLogger } from "../../telemetry/logs";
import { getCloudCredentials } from "../utils";

export async function deleteApp(appName: string, host: string, port: string): Promise<number> {
const logger = createGlobalLogger();
const logger = new GlobalLogger();
const userCredentials = getCloudCredentials();
const bearerToken = "Bearer " + userCredentials.token;

Expand Down
4 changes: 2 additions & 2 deletions src/cloud-cli/applications/deploy-app-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import axios from "axios";
import YAML from "yaml";
import { execSync } from "child_process";
import fs from "fs";
import { createGlobalLogger } from "../../telemetry/logs";
import { GlobalLogger } from "../../telemetry/logs";
import { getCloudCredentials } from "../utils";
import { createDirectory, readFileSync } from "../../utils";
import { ConfigFile, loadConfigFile, dbosConfigFilePath } from "../../dbos-runtime/config";

const deployDirectoryName = "dbos_deploy";

export async function deployAppCode(appName: string, host: string, port: string): Promise<number> {
const logger = createGlobalLogger();
const logger = new GlobalLogger();
const userCredentials = getCloudCredentials();
const bearerToken = "Bearer " + userCredentials.token;

Expand Down
7 changes: 4 additions & 3 deletions src/cloud-cli/applications/get-app-logs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import axios from "axios";
import { createGlobalLogger } from "../../telemetry/logs";
import { GlobalLogger } from "../../telemetry/logs";
import { getCloudCredentials } from "../utils";

export async function getAppLogs(appName: string, host: string, port: string): Promise<number> {
const logger = createGlobalLogger();
const logger = new GlobalLogger();
const userCredentials = getCloudCredentials();
const bearerToken = "Bearer " + userCredentials.token;

Expand All @@ -16,7 +16,8 @@ export async function getAppLogs(appName: string, host: string, port: string): P
});

logger.info(`Successfully retrieved logs of application: ${appName}`);
logger.info(res.data)
// FIXME: AxiosResponse is a generic type. We should generate our client using OpenAPI. Use string for now
logger.info(res.data as string)
return 0;
} catch (e) {
if (axios.isAxiosError(e) && e.response) {
Expand Down
4 changes: 2 additions & 2 deletions src/cloud-cli/applications/list-apps.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import axios from "axios";
import { createGlobalLogger } from "../../telemetry/logs";
import { GlobalLogger } from "../../telemetry/logs";
import { getCloudCredentials } from "../utils";
import { Application } from "./types";

export async function listApps(host: string, port: string): Promise<number> {
const logger = createGlobalLogger();
const logger = new GlobalLogger();
const userCredentials = getCloudCredentials();
const bearerToken = "Bearer " + userCredentials.token;

Expand Down
4 changes: 2 additions & 2 deletions src/cloud-cli/applications/register-app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import axios from "axios";
import { createGlobalLogger } from "../../telemetry/logs";
import { GlobalLogger } from "../../telemetry/logs";
import { getCloudCredentials } from "../utils";

export async function registerApp(appName: string, host: string, port: string, machines: number): Promise<number> {
const logger = createGlobalLogger();
const logger = new GlobalLogger();
const userCredentials = getCloudCredentials();
const bearerToken = "Bearer " + userCredentials.token;

Expand Down
4 changes: 2 additions & 2 deletions src/cloud-cli/applications/update-app.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import axios from "axios";
import { createGlobalLogger } from "../../telemetry/logs";
import { GlobalLogger } from "../../telemetry/logs";
import { getCloudCredentials } from "../utils";
import { Application } from "./types";

export async function updateApp(appName: string, host: string, port: string, machines: number): Promise<number> {
const logger = createGlobalLogger();
const logger = new GlobalLogger();
const userCredentials = getCloudCredentials();
const bearerToken = "Bearer " + userCredentials.token;

Expand Down
8 changes: 4 additions & 4 deletions src/cloud-cli/login.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createGlobalLogger } from "../telemetry/logs";
import { GlobalLogger } from "../telemetry/logs";
import axios from "axios";
import { sleep } from "../utils";
import jwt, { JwtPayload } from 'jsonwebtoken';
Expand Down Expand Up @@ -60,7 +60,7 @@ async function verifyToken(token: string): Promise<JwtPayload> {
}

export async function login(username: string): Promise<number> {
const logger = createGlobalLogger();
const logger = new GlobalLogger();
logger.info(`Logging in!`);

const deviceCodeRequest = {
Expand All @@ -74,7 +74,7 @@ export async function login(username: string): Promise<number> {
const response = await axios.request(deviceCodeRequest);
deviceCodeResponse = response.data as DeviceCodeResponse;
} catch (e) {
logger.error(`failed to log in`, e);
logger.error(new Error(`failed to log in: ${(e as Error).message}`));
}
if (!deviceCodeResponse) {
return 1;
Expand Down Expand Up @@ -112,7 +112,7 @@ export async function login(username: string): Promise<number> {
const credentials: DBOSCloudCredentials = {
token: tokenResponse.access_token,
userName: username,
}
};
execSync(`mkdir -p ${dbosEnvPath}`);
fs.writeFileSync(`${dbosEnvPath}/credentials`, JSON.stringify(credentials), "utf-8");
logger.info(`Successfully logged in as user: ${credentials.userName}`);
Expand Down
4 changes: 2 additions & 2 deletions src/cloud-cli/register.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import axios from "axios";
import { createGlobalLogger } from "../telemetry/logs";
import { GlobalLogger } from "../telemetry/logs";
import { getCloudCredentials } from "./utils";

export async function registerUser(username: string, host: string, port: string): Promise<number> {
const userCredentials = getCloudCredentials();
const bearerToken = "Bearer " + userCredentials.token;
const userName = userCredentials.userName;
const logger = createGlobalLogger();
const logger = new GlobalLogger();
try {
// First, register the user.
const register = await axios.put(
Expand Down
21 changes: 10 additions & 11 deletions src/cloud-cli/userdb.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import axios from "axios";
import { createGlobalLogger } from "../telemetry/logs";
import { GlobalLogger } from "../telemetry/logs";
import { getCloudCredentials } from "./utils";
import { sleep } from "../utils";
import { ConfigFile, loadConfigFile, dbosConfigFilePath } from "../dbos-runtime/config";
import { execSync } from "child_process";

export async function createUserDb(host: string, port: string, dbName: string, adminName: string, adminPassword: string, sync: boolean) {
const logger = createGlobalLogger();
const logger = new GlobalLogger();
const userCredentials = getCloudCredentials();
const bearerToken = "Bearer " + userCredentials.token;

Expand All @@ -32,7 +32,7 @@ export async function createUserDb(host: string, port: string, dbName: string, a
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
data = await getDb(host, port, dbName);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
logger.info(data);
logger.info(data as string);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
status = data.Status;
}
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function createUserDb(host: string, port: string, dbName: string, a
}

export async function deleteUserDb(host: string, port: string, dbName: string, sync: boolean) {
const logger = createGlobalLogger();
const logger = new GlobalLogger();
const userCredentials = getCloudCredentials();
const bearerToken = "Bearer " + userCredentials.token;

Expand Down Expand Up @@ -94,7 +94,7 @@ export async function deleteUserDb(host: string, port: string, dbName: string, s
break;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
logger.info(data);
logger.info(data as string);
maxdml marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
status = data.Status;
}
Expand Down Expand Up @@ -122,12 +122,12 @@ export async function deleteUserDb(host: string, port: string, dbName: string, s
}

export async function getUserDb(host: string, port: string, dbName: string) {
const logger = createGlobalLogger();
const logger = new GlobalLogger();

try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const res = await getDb(host, port, dbName);
logger.info(res);
logger.info(res as string);
} catch (e) {
if (axios.isAxiosError(e) && e.response) {
logger.error(`Error getting database ${dbName}: ${e.response?.data}`);
Expand All @@ -138,7 +138,7 @@ export async function getUserDb(host: string, port: string, dbName: string) {
}

export function migrate(): number {
const logger = createGlobalLogger();
const logger = new GlobalLogger();

// read the yaml file
const configFile: ConfigFile | undefined = loadConfigFile(dbosConfigFilePath);
Expand Down Expand Up @@ -199,8 +199,7 @@ export function migrate(): number {
logger.error(e.message);
}
} else {
// If 'e' is not an Error object, log it as a generic error
logger.error('An unknown error occurred:', e);
logger.error(e);
}
return 1;
}
Expand All @@ -209,7 +208,7 @@ export function migrate(): number {
}

export function rollbackmigration(): number {
const logger = createGlobalLogger();
const logger = new GlobalLogger();

// read the yaml file
const configFile: ConfigFile | undefined = loadConfigFile(dbosConfigFilePath);
Expand Down
2 changes: 1 addition & 1 deletion src/communicator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Span } from "@opentelemetry/sdk-trace-base";
import { WinstonLogger as Logger } from "./telemetry/logs";
import { GlobalLogger as Logger } from "./telemetry/logs";
import { WorkflowContextImpl } from "./workflow";
import { DBOSContext, DBOSContextImpl } from "./context";
import { WorkflowContextDebug } from "./debugger/debug_workflow";
Expand Down
4 changes: 2 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Span } from "@opentelemetry/sdk-trace-base";
import { WinstonLogger as Logger, Logger as DBOSLogger } from "./telemetry/logs";
import { GlobalLogger as Logger, Logger as DBOSLogger } from "./telemetry/logs";
import { has, get } from "lodash";
import { IncomingHttpHeaders } from "http";
import { ParsedUrlQuery } from "querystring";
Expand Down Expand Up @@ -44,14 +44,14 @@ export class DBOSContextImpl implements DBOSContext {
readonly logger: DBOSLogger; // Wrapper around the global logger for this context.

constructor(readonly operationName: string, readonly span: Span, logger: Logger, parentCtx?: DBOSContextImpl) {
this.logger = new DBOSLogger(logger, this);
if (parentCtx) {
this.request = parentCtx.request;
this.authenticatedUser = parentCtx.authenticatedUser;
this.authenticatedRoles = parentCtx.authenticatedRoles;
this.assumedRole = parentCtx.assumedRole;
this.workflowUUID = parentCtx.workflowUUID;
}
this.logger = new DBOSLogger(logger, this);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix a bug where the metadata would be missing if provided from the parentCtx

}

/*** Application configuration ***/
Expand Down
Loading
Loading