GithubHelp home page GithubHelp logo

Comments (2)

nirsky avatar nirsky commented on May 12, 2024

Hey @julien-sugg,

Can you provide some code snippets which result in uninstrumented code?
I want to assess the required effort

from opentelemetry-ext-js.

julien-sugg avatar julien-sugg commented on May 12, 2024

Hi @nirsky,

Thanks for your quick response, I cannot share the real code because it is a closed-source project. However, I can share some redacted content.

Ecosystem:

  • NestJS 7.X
  • pg driver 8.3.0 + TypeORM 0.2.25 (using NestJS TypeORM integration that acts more or less as a wrapper around TypeORM 7.X)

The simplest use-case that we would like to instrument is the read model (query) which is done though a two layer style architecture using the TypeORM SelectQueryBuilder

// foo.controller.ts
@Controller( 'foo' )
export class FooController {
  constructor(
    private readonly commandBus: CommandBus,
    private readonly queryBus: QueryBus
  ) {}

  @Get()
  async list(
      @Query( QueryParamEnum.page ) page?: number,
      @Query( QueryParamEnum.perPage ) perPage?: number,
      @Query( QueryParamEnum.sortBy ) sort?: Sort[],
      @Query( QueryParamEnum.filterBy ) filter?: Where,
  ): Promise<GetFooListDtoPresentation> {
    return this.queryBus.execute<redacted>(
      new GetFooListQuery(
        page,
        perPage,
        sort,
        filter,
      ),
    );
  }
}
// foo.query.ts
export class GetFooListQuery implements IQuery,
  PagedQueryInterface,
  SortedQueryInterface,
  FilteredQueryInterface {
  constructor(
  ) {
  }
}
// foo.query-handler.ts
@QueryHandler( GetFooListQuery )
export class GetFooListQueryHandler
  extends QueryableQueryHandler
  implements IQueryHandler<GetFooListQuery, FooListDto> {
  private readonly entityManager: EntityManager;

  constructor(
    @InjectEntityManager()
    entityManager: EntityManager,
  ) {
    super();
    this.entityManager = entityManager;
  }

  async execute( query: ContextualGetFooListQuery ): Promise<FooListDto> {
    const queryBuilder = this.entityManager
      .createQueryBuilder( FooEntity, 'foo' )
      .leftJoinAndSelect( 'foo.bar', 'bar' );

    const pageData = PageQueryHelper.getPageData( query );
    GetFooListQueryHandler.applyQueryingLogic(
      queryBuilder,
      pageData,
      query,
    );
    const [
      fooRecords,
      totalRecords,
    ] = await queryBuilder.getManyAndCount();

    // Redacted mapper

    return {
      records: fooRecords,
      page: pageData.offset,
      perPage: pageData.next,
      totalRecords,
    };
  }
}

We also have similar instrumentation troubles on the write model (command) which is done through a multi-layered clean architecture style implementation.

// foo.repository.ts
@Injectable()
export class FooRepository implements FooRepositoryInterface {
  private readonly fooRepository: Repository<FooEntity>;

  constructor(
  @InjectRepository( FooEntity )
    fooRepository: Repository<FooEntity>,
  ) {
    this.fooRepository = fooRepository;
  }

  // Here foo is an AggregateRoot, but it has no impact on the understanding as we have a mapper to convert from aggregate to DAO
  async save( foo: Foo ): Promise<void> {
    const fooDAO = FooMapper.toPersistence( foo );
    await this.fooRepository.save( fooDAO );
  }
}

If this is not helpful enough, I can create a minimalist repo for reproduction with a docker-compose stack.

from opentelemetry-ext-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.