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

Ioredis cleanup #194

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion plugins/node/opentelemetry-plugin-ioredis/src/ioredis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { BasePlugin } from '@opentelemetry/core';
import * as ioredisTypes from 'ioredis';
import type * as ioredisTypes from 'ioredis';
import * as shimmer from 'shimmer';
import { IoredisPluginConfig } from './types';
import { traceConnection, traceSendCommand } from './utils';
Expand Down
7 changes: 1 addition & 6 deletions plugins/node/opentelemetry-plugin-ioredis/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import * as ioredisTypes from 'ioredis';
import type * as ioredisTypes from 'ioredis';
import { PluginConfig } from '@opentelemetry/api';

export interface IoredisCommand {
Expand All @@ -26,11 +26,6 @@ export interface IoredisCommand {
name: string;
}

export interface IoredisPluginClientTypes {
// https:/luin/ioredis/blob/master/API.md
options: ioredisTypes.RedisOptions;
}

/**
* Function that can be used to serialize db.statement tag
* @param cmdName - The name of the command (eg. set, get, mset)
Expand Down
10 changes: 3 additions & 7 deletions plugins/node/opentelemetry-plugin-ioredis/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
* limitations under the License.
*/

import * as ioredisTypes from 'ioredis';
import type * as ioredisTypes from 'ioredis';
import { Tracer, SpanKind, Span, CanonicalCode } from '@opentelemetry/api';
import {
IoredisPluginClientTypes,
IoredisCommand,
IoredisPluginConfig,
DbStatementSerializer,
Expand All @@ -41,7 +40,7 @@ const endSpan = (span: Span, err: NodeJS.ErrnoException | null | undefined) => {
};

export const traceConnection = (tracer: Tracer, original: Function) => {
return function (this: ioredisTypes.Redis & IoredisPluginClientTypes) {
return function (this: ioredisTypes.Redis) {
const span = tracer.startSpan('connect', {
kind: SpanKind.CLIENT,
attributes: {
Expand Down Expand Up @@ -82,10 +81,7 @@ export const traceSendCommand = (
) => {
const dbStatementSerializer =
config?.dbStatementSerializer || defaultDbStatementSerializer;
return function (
this: ioredisTypes.Redis & IoredisPluginClientTypes,
cmd?: IoredisCommand
) {
return function (this: ioredisTypes.Redis, cmd?: IoredisCommand) {
if (arguments.length < 1 || typeof cmd !== 'object') {
return original.apply(this, arguments);
}
Expand Down