From a1705d669a0c10be7ed6c79fd33f0b2c1e07fb14 Mon Sep 17 00:00:00 2001 From: nicu-da Date: Fri, 26 Nov 2021 03:12:17 -0800 Subject: [PATCH] participant-state - Add an implicit logging context to the write service [kvl-1072] (#11838) changelog_begin changelog_end --- .../ApiConfigManagementServiceSpec.scala | 10 +++++-- .../ApiPackageManagementServiceSpec.scala | 5 +++- .../admin/ApiPartyManagementServiceSpec.scala | 5 +++- .../LedgerConfigurationProvisionerSpec.scala | 10 +++---- .../services/ApiSubmissionServiceSpec.scala | 12 ++++----- .../state/v2/metrics/TimedWriteService.scala | 21 ++++++++++++--- .../state/kvutils/app/Runner.scala | 8 ++++-- .../api/KeyValueParticipantState.scala | 20 +++++++++++--- .../api/KeyValueParticipantStateWriter.scala | 27 ++++++++++++++----- .../KeyValueParticipantStateWriterSpec.scala | 1 + .../state/v2/WriteConfigService.scala | 7 +++-- .../state/v2/WritePackagesService.scala | 7 +++-- .../state/v2/WritePartyService.scala | 7 +++-- .../participant/state/v2/WriteService.scala | 7 +++-- .../stores/LedgerBackedWriteService.scala | 22 ++++++++++----- .../sandbox/ReadWriteServiceBridge.scala | 20 +++++++++++--- .../scala/platform/sandboxnext/Runner.scala | 6 +++-- 17 files changed, 143 insertions(+), 52 deletions(-) diff --git a/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiConfigManagementServiceSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiConfigManagementServiceSpec.scala index 7e0eb500c0c..58b009f6aa5 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiConfigManagementServiceSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiConfigManagementServiceSpec.scala @@ -336,7 +336,10 @@ object ApiConfigManagementServiceSpec { maxRecordTime: Time.Timestamp, submissionId: Ref.SubmissionId, config: Configuration, - )(implicit telemetryContext: TelemetryContext): CompletionStage[state.SubmissionResult] = { + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[state.SubmissionResult] = { telemetryContext.setAttribute( anApplicationIdSpanAttribute._1, anApplicationIdSpanAttribute._2, @@ -389,7 +392,10 @@ object ApiConfigManagementServiceSpec { maxRecordTime: Time.Timestamp, submissionId: SubmissionId, configuration: Configuration, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = { + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = { configurationQueue.offer((currentOffset.getAndIncrement(), submissionId, configuration)) completedFuture(state.SubmissionResult.Acknowledged) } diff --git a/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPackageManagementServiceSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPackageManagementServiceSpec.scala index d4c7ccfb18f..76ae219f562 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPackageManagementServiceSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPackageManagementServiceSpec.scala @@ -132,7 +132,10 @@ object ApiPackageManagementServiceSpec { submissionId: Ref.SubmissionId, archives: List[DamlLf.Archive], sourceDescription: Option[String], - )(implicit telemetryContext: TelemetryContext): CompletionStage[state.SubmissionResult] = { + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[state.SubmissionResult] = { telemetryContext.setAttribute( anApplicationIdSpanAttribute._1, anApplicationIdSpanAttribute._2, diff --git a/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPartyManagementServiceSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPartyManagementServiceSpec.scala index 82abb9591bf..698d386e262 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPartyManagementServiceSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPartyManagementServiceSpec.scala @@ -89,7 +89,10 @@ object ApiPartyManagementServiceSpec { hint: Option[Ref.Party], displayName: Option[String], submissionId: Ref.SubmissionId, - )(implicit telemetryContext: TelemetryContext): CompletionStage[state.SubmissionResult] = { + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[state.SubmissionResult] = { telemetryContext.setAttribute( anApplicationIdSpanAttribute._1, anApplicationIdSpanAttribute._2, diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/configuration/LedgerConfigurationProvisionerSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/configuration/LedgerConfigurationProvisionerSpec.scala index d055a08b706..cc73d330a3e 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/configuration/LedgerConfigurationProvisionerSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/configuration/LedgerConfigurationProvisionerSpec.scala @@ -73,7 +73,7 @@ final class LedgerConfigurationProvisionerSpec any[Timestamp], any[Ref.SubmissionId], any[Configuration], - )(any[TelemetryContext]) + )(any[LoggingContext], any[TelemetryContext]) scheduler.timePasses(100.millis) eventually { @@ -81,7 +81,7 @@ final class LedgerConfigurationProvisionerSpec eqTo(Timestamp.assertFromInstant(timeProvider.getCurrentTime.plusSeconds(60))), eqTo(submissionId), eqTo(configurationToSubmit), - )(any[TelemetryContext]) + )(any[LoggingContext], any[TelemetryContext]) } succeed } @@ -115,7 +115,7 @@ final class LedgerConfigurationProvisionerSpec any[Timestamp], any[Ref.SubmissionId], any[Configuration], - )(any[TelemetryContext]) + )(any[LoggingContext], any[TelemetryContext]) succeed } } @@ -158,7 +158,7 @@ final class LedgerConfigurationProvisionerSpec any[Timestamp], any[Ref.SubmissionId], any[Configuration], - )(any[TelemetryContext]) + )(any[LoggingContext], any[TelemetryContext]) succeed } } @@ -192,7 +192,7 @@ final class LedgerConfigurationProvisionerSpec any[Timestamp], any[Ref.SubmissionId], any[Configuration], - )(any[TelemetryContext]) + )(any[LoggingContext], any[TelemetryContext]) succeed } } diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/services/ApiSubmissionServiceSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/services/ApiSubmissionServiceSpec.scala index ac17d790c72..d39fab7856b 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/services/ApiSubmissionServiceSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/services/ApiSubmissionServiceSpec.scala @@ -102,7 +102,7 @@ class ApiSubmissionServiceSpec any[Option[Ref.Party]], any[Option[Ref.Party]], any[Ref.SubmissionId], - )(any[TelemetryContext]) + )(any[LoggingContext], any[TelemetryContext]) ).thenReturn(completedFuture(state.SubmissionResult.Acknowledged)) val service = @@ -118,7 +118,7 @@ class ApiSubmissionServiceSpec eqTo(Some(Ref.Party.assertFromString(party))), eqTo(Some(party)), any[Ref.SubmissionId], - )(any[TelemetryContext]) + )(any[LoggingContext], any[TelemetryContext]) } verifyNoMoreInteractions(writeService) succeed @@ -137,7 +137,7 @@ class ApiSubmissionServiceSpec any[Option[Ref.Party]], any[Option[Ref.Party]], any[Ref.SubmissionId], - )(any[TelemetryContext]) + )(any[LoggingContext], any[TelemetryContext]) ).thenReturn(completedFuture(state.SubmissionResult.Acknowledged)) val service = @@ -151,7 +151,7 @@ class ApiSubmissionServiceSpec any[Option[Ref.Party]], any[Option[String]], any[Ref.SubmissionId], - )(any[TelemetryContext]) + )(any[LoggingContext], any[TelemetryContext]) succeed } } @@ -173,7 +173,7 @@ class ApiSubmissionServiceSpec any[Option[Ref.Party]], any[Option[String]], any[Ref.SubmissionId], - )(any[TelemetryContext]) + )(any[LoggingContext], any[TelemetryContext]) succeed } } @@ -192,7 +192,7 @@ class ApiSubmissionServiceSpec eqTo(Some(typedParty)), eqTo(Some(party)), any[Ref.SubmissionId], - )(any[TelemetryContext]) + )(any[LoggingContext], any[TelemetryContext]) ).thenReturn(completedFuture(submissionFailure)) when(partyManagementService.getParties(Seq(typedParty))) .thenReturn(Future(List.empty[PartyDetails])) diff --git a/ledger/participant-state-metrics/src/main/scala/com/daml/ledger/participant/state/v2/metrics/TimedWriteService.scala b/ledger/participant-state-metrics/src/main/scala/com/daml/ledger/participant/state/v2/metrics/TimedWriteService.scala index b6631aa758f..d9edd20a679 100644 --- a/ledger/participant-state-metrics/src/main/scala/com/daml/ledger/participant/state/v2/metrics/TimedWriteService.scala +++ b/ledger/participant-state-metrics/src/main/scala/com/daml/ledger/participant/state/v2/metrics/TimedWriteService.scala @@ -18,6 +18,7 @@ import com.daml.ledger.participant.state.v2.{ } import com.daml.lf.data.{Ref, Time} import com.daml.lf.transaction.SubmittedTransaction +import com.daml.logging.LoggingContext import com.daml.metrics.{Metrics, Timed} import com.daml.telemetry.TelemetryContext @@ -28,7 +29,10 @@ final class TimedWriteService(delegate: WriteService, metrics: Metrics) extends transactionMeta: TransactionMeta, transaction: SubmittedTransaction, estimatedInterpretationCost: Long, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = Timed.timedAndTrackedCompletionStage( metrics.daml.services.write.submitTransaction, metrics.daml.services.write.submitTransactionRunning, @@ -44,7 +48,10 @@ final class TimedWriteService(delegate: WriteService, metrics: Metrics) extends submissionId: Ref.SubmissionId, archives: List[DamlLf.Archive], sourceDescription: Option[String], - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = Timed.completionStage( metrics.daml.services.write.uploadPackages, delegate.uploadPackages(submissionId, archives, sourceDescription), @@ -54,7 +61,10 @@ final class TimedWriteService(delegate: WriteService, metrics: Metrics) extends hint: Option[Ref.Party], displayName: Option[String], submissionId: Ref.SubmissionId, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = Timed.completionStage( metrics.daml.services.write.allocateParty, delegate.allocateParty(hint, displayName, submissionId), @@ -64,7 +74,10 @@ final class TimedWriteService(delegate: WriteService, metrics: Metrics) extends maxRecordTime: Time.Timestamp, submissionId: Ref.SubmissionId, config: Configuration, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = Timed.completionStage( metrics.daml.services.write.submitConfiguration, delegate.submitConfiguration(maxRecordTime, submissionId, config), diff --git a/ledger/participant-state/kvutils/app/src/main/scala/com/daml/ledger/participant/state/kvutils/app/Runner.scala b/ledger/participant-state/kvutils/app/src/main/scala/com/daml/ledger/participant/state/kvutils/app/Runner.scala index e7d3d7fcb00..be07c8fbc51 100644 --- a/ledger/participant-state/kvutils/app/src/main/scala/com/daml/ledger/participant/state/kvutils/app/Runner.scala +++ b/ledger/participant-state/kvutils/app/src/main/scala/com/daml/ledger/participant/state/kvutils/app/Runner.scala @@ -134,7 +134,10 @@ final class Runner[T <: ReadWriteService, Extra]( _ <- Resource.sequence( config.archiveFiles.map(path => Resource.fromFuture( - uploadDar(path, writeService)(resourceContext.executionContext) + uploadDar(path, writeService)( + loggingContext, + resourceContext.executionContext, + ) ) ) ) @@ -198,7 +201,8 @@ final class Runner[T <: ReadWriteService, Extra]( } private def uploadDar(from: Path, to: WritePackagesService)(implicit - executionContext: ExecutionContext + loggingContext: LoggingContext, + executionContext: ExecutionContext, ): Future[Unit] = DefaultTelemetry.runFutureInSpan(SpanName.RunnerUploadDar, SpanKind.Internal) { implicit telemetryContext => val submissionId = Ref.SubmissionId.assertFromString(UUID.randomUUID().toString) diff --git a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantState.scala b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantState.scala index 48731154765..39e50709d88 100644 --- a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantState.scala +++ b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantState.scala @@ -67,7 +67,10 @@ class KeyValueParticipantState( transactionMeta: TransactionMeta, transaction: SubmittedTransaction, estimatedInterpretationCost: Long, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = writerAdapter.submitTransaction( submitterInfo, transactionMeta, @@ -79,21 +82,30 @@ class KeyValueParticipantState( maxRecordTime: Time.Timestamp, submissionId: Ref.SubmissionId, config: Configuration, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = writerAdapter.submitConfiguration(maxRecordTime, submissionId, config) override def uploadPackages( submissionId: Ref.SubmissionId, archives: List[DamlLf.Archive], sourceDescription: Option[String], - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = writerAdapter.uploadPackages(submissionId, archives, sourceDescription) override def allocateParty( hint: Option[Ref.Party], displayName: Option[String], submissionId: Ref.SubmissionId, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = writerAdapter.allocateParty(hint, displayName, submissionId) override def prune( diff --git a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateWriter.scala b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateWriter.scala index 29e3056709d..46d7e9f4328 100644 --- a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateWriter.scala +++ b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateWriter.scala @@ -5,6 +5,7 @@ package com.daml.ledger.participant.state.kvutils.api import java.util.UUID import java.util.concurrent.{CompletableFuture, CompletionStage} + import com.daml.daml_lf_dev.DamlLf import com.daml.ledger.api.health.HealthStatus import com.daml.ledger.configuration.Configuration @@ -14,8 +15,8 @@ import com.daml.ledger.participant.state.kvutils.{Envelope, KeyValueSubmission} import com.daml.ledger.participant.state.v2._ import com.daml.lf.data.{Ref, Time} import com.daml.lf.transaction.SubmittedTransaction -import com.daml.logging.ContextualizedLogger -import com.daml.logging.LoggingContext.newLoggingContextWith +import com.daml.logging.LoggingContext.withEnrichedLoggingContext +import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.metrics.Metrics import com.daml.telemetry.TelemetryContext @@ -36,7 +37,10 @@ class KeyValueParticipantStateWriter( transactionMeta: TransactionMeta, transaction: SubmittedTransaction, estimatedInterpretationCost: Long, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = { + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = { val submission = keyValueSubmission.transactionToSubmission( submitterInfo, @@ -45,7 +49,7 @@ class KeyValueParticipantStateWriter( ) val metadata = CommitMetadata(submission, Some(estimatedInterpretationCost)) val submissionId = submitterInfo.submissionId.getOrElse { - newLoggingContextWith( + withEnrichedLoggingContext( "commandId" -> submitterInfo.commandId, "applicationId" -> submitterInfo.applicationId, ) { implicit loggingContext => @@ -65,7 +69,10 @@ class KeyValueParticipantStateWriter( submissionId: Ref.SubmissionId, archives: List[DamlLf.Archive], sourceDescription: Option[String], - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = { + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = { val submission = keyValueSubmission .archivesToSubmission( submissionId, @@ -80,7 +87,10 @@ class KeyValueParticipantStateWriter( maxRecordTime: Time.Timestamp, submissionId: Ref.SubmissionId, config: Configuration, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = { + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = { val submission = keyValueSubmission .configurationToSubmission(maxRecordTime, submissionId, writer.participantId, config) @@ -91,7 +101,10 @@ class KeyValueParticipantStateWriter( hint: Option[Ref.Party], displayName: Option[String], submissionId: Ref.SubmissionId, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = { + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = { val party = hint.getOrElse(generateRandomParty()) val submission = keyValueSubmission.partyToSubmission( diff --git a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateWriterSpec.scala b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateWriterSpec.scala index 2e906e2da57..de266718a93 100644 --- a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateWriterSpec.scala +++ b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateWriterSpec.scala @@ -37,6 +37,7 @@ class KeyValueParticipantStateWriterSpec with ArgumentMatchersSugar { import KeyValueParticipantStateWriterSpec._ + private implicit val loggingContext = com.daml.logging.LoggingContext.ForTesting "participant state writer" should { "submit a transaction" in { diff --git a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WriteConfigService.scala b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WriteConfigService.scala index 99342b8e452..c6c697bb7c6 100644 --- a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WriteConfigService.scala +++ b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WriteConfigService.scala @@ -8,6 +8,7 @@ import java.util.concurrent.CompletionStage import com.daml.ledger.configuration.Configuration import com.daml.lf.data.Ref import com.daml.lf.data.Time.Timestamp +import com.daml.logging.LoggingContext import com.daml.telemetry.TelemetryContext trait WriteConfigService { @@ -26,12 +27,14 @@ trait WriteConfigService { * @param maxRecordTime: The maximum record time after which the request is rejected. * @param submissionId: Client picked submission identifier for matching the responses with the request. * @param config: The new ledger configuration. - * @param telemetryContext: An implicit context for tracing. * @return an async result of a SubmissionResult */ def submitConfiguration( maxRecordTime: Timestamp, submissionId: Ref.SubmissionId, config: Configuration, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] } diff --git a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WritePackagesService.scala b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WritePackagesService.scala index e9191c1c948..3a018bdc10f 100644 --- a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WritePackagesService.scala +++ b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WritePackagesService.scala @@ -7,6 +7,7 @@ import java.util.concurrent.CompletionStage import com.daml.daml_lf_dev.DamlLf.Archive import com.daml.lf.data.Ref +import com.daml.logging.LoggingContext import com.daml.telemetry.TelemetryContext /** An interface for uploading packages via a participant. */ @@ -37,7 +38,6 @@ trait WritePackagesService { * @param archives Daml-LF archives to be uploaded to the ledger. * All archives must be valid, i.e., they must successfully decode and pass * Daml engine validation. - * @param telemetryContext An implicit context for tracing. * * @return an async result of a [[SubmissionResult]] */ @@ -45,5 +45,8 @@ trait WritePackagesService { submissionId: Ref.SubmissionId, archives: List[Archive], sourceDescription: Option[String], - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] } diff --git a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WritePartyService.scala b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WritePartyService.scala index 1e90645998c..2000cdc14a5 100644 --- a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WritePartyService.scala +++ b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WritePartyService.scala @@ -6,6 +6,7 @@ package com.daml.ledger.participant.state.v2 import java.util.concurrent.CompletionStage import com.daml.lf.data.Ref +import com.daml.logging.LoggingContext import com.daml.telemetry.TelemetryContext /** An interface for on-boarding parties via a participant. */ @@ -28,7 +29,6 @@ trait WritePartyService { * @param hint A party identifier suggestion * @param displayName A human readable name of the new party * @param submissionId Client picked submission identifier for matching the responses with the request. - * @param telemetryContext An implicit context for tracing. * * @return an async result of a SubmissionResult */ @@ -36,5 +36,8 @@ trait WritePartyService { hint: Option[Ref.Party], displayName: Option[String], submissionId: Ref.SubmissionId, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] } diff --git a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WriteService.scala b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WriteService.scala index b4b3d963676..02d1949dcf4 100644 --- a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WriteService.scala +++ b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/WriteService.scala @@ -7,6 +7,7 @@ import java.util.concurrent.CompletionStage import com.daml.ledger.api.health.ReportsHealth import com.daml.lf.transaction.SubmittedTransaction +import com.daml.logging.LoggingContext import com.daml.telemetry.TelemetryContext /** An interface to change a ledger via a participant. @@ -94,14 +95,16 @@ trait WriteService * daml-lf/spec/contract-id.rst. * @param estimatedInterpretationCost Estimated cost of interpretation that may be used for * handling submitted transactions differently. - * @param telemetryContext Implicit context for tracing. */ def submitTransaction( submitterInfo: SubmitterInfo, transactionMeta: TransactionMeta, transaction: SubmittedTransaction, estimatedInterpretationCost: Long, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] /** Indicates whether command deduplication should be enabled when using this [[WriteService]] * This is temporary until we fully transition from [[com.daml.ledger.participant.state.v1.WriteService]] to [[WriteService]] diff --git a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/LedgerBackedWriteService.scala b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/LedgerBackedWriteService.scala index 5a4d3336a05..e3598cf88d4 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/LedgerBackedWriteService.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/LedgerBackedWriteService.scala @@ -25,8 +25,6 @@ private[stores] final class LedgerBackedWriteService( ledger: Ledger, timeProvider: TimeProvider, enablePruning: Boolean, -)(implicit - loggingContext: LoggingContext ) extends state.WriteService { override def currentHealth(): HealthStatus = ledger.currentHealth() @@ -36,7 +34,10 @@ private[stores] final class LedgerBackedWriteService( transactionMeta: state.TransactionMeta, transaction: SubmittedTransaction, estimatedInterpretationCost: Long, - )(implicit telemetryContext: TelemetryContext): CompletionStage[state.SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[state.SubmissionResult] = withEnrichedLoggingContext( "actAs" -> submitterInfo.actAs, "applicationId" -> submitterInfo.applicationId, @@ -55,7 +56,10 @@ private[stores] final class LedgerBackedWriteService( hint: Option[Ref.Party], displayName: Option[String], submissionId: Ref.SubmissionId, - )(implicit telemetryContext: TelemetryContext): CompletionStage[state.SubmissionResult] = { + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[state.SubmissionResult] = { val party = hint.getOrElse(PartyIdGenerator.generateRandomId()) withEnrichedLoggingContext( "party" -> party, @@ -70,7 +74,10 @@ private[stores] final class LedgerBackedWriteService( submissionId: Ref.SubmissionId, payload: List[DamlLf.Archive], sourceDescription: Option[String], - )(implicit telemetryContext: TelemetryContext): CompletionStage[state.SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[state.SubmissionResult] = withEnrichedLoggingContext( "submissionId" -> submissionId, "description" -> sourceDescription, @@ -91,7 +98,10 @@ private[stores] final class LedgerBackedWriteService( maxRecordTime: Time.Timestamp, submissionId: Ref.SubmissionId, config: Configuration, - )(implicit telemetryContext: TelemetryContext): CompletionStage[state.SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[state.SubmissionResult] = withEnrichedLoggingContext( "maxRecordTime" -> maxRecordTime.toInstant, "submissionId" -> submissionId, diff --git a/ledger/sandbox-on-x/src/main/scala/com/daml/ledger/sandbox/ReadWriteServiceBridge.scala b/ledger/sandbox-on-x/src/main/scala/com/daml/ledger/sandbox/ReadWriteServiceBridge.scala index d4bf4db3b0a..1f362d33e14 100644 --- a/ledger/sandbox-on-x/src/main/scala/com/daml/ledger/sandbox/ReadWriteServiceBridge.scala +++ b/ledger/sandbox-on-x/src/main/scala/com/daml/ledger/sandbox/ReadWriteServiceBridge.scala @@ -56,7 +56,10 @@ case class ReadWriteServiceBridge( transactionMeta: TransactionMeta, transaction: SubmittedTransaction, estimatedInterpretationCost: Long, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = submit( Submission.Transaction( submitterInfo = submitterInfo, @@ -70,7 +73,10 @@ case class ReadWriteServiceBridge( maxRecordTime: Time.Timestamp, submissionId: Ref.SubmissionId, config: Configuration, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = submit( Submission.Config( maxRecordTime = maxRecordTime, @@ -85,7 +91,10 @@ case class ReadWriteServiceBridge( hint: Option[Ref.Party], displayName: Option[String], submissionId: Ref.SubmissionId, - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = submit( Submission.AllocateParty( hint = hint, @@ -98,7 +107,10 @@ case class ReadWriteServiceBridge( submissionId: Ref.SubmissionId, archives: List[Archive], sourceDescription: Option[String], - )(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = + )(implicit + loggingContext: LoggingContext, + telemetryContext: TelemetryContext, + ): CompletionStage[SubmissionResult] = submit( Submission.UploadPackages( submissionId = submissionId, diff --git a/ledger/sandbox/src/main/scala/platform/sandboxnext/Runner.scala b/ledger/sandbox/src/main/scala/platform/sandboxnext/Runner.scala index 18890a14d1c..f686fe29399 100644 --- a/ledger/sandbox/src/main/scala/platform/sandboxnext/Runner.scala +++ b/ledger/sandbox/src/main/scala/platform/sandboxnext/Runner.scala @@ -7,6 +7,7 @@ import java.io.File import java.time.{Clock, Instant} import java.util.UUID import java.util.concurrent.Executors + import akka.actor.ActorSystem import akka.stream.Materializer import com.daml.api.util.TimeProvider @@ -32,7 +33,7 @@ import com.daml.lf.archive.DarParser import com.daml.lf.data.Ref import com.daml.lf.engine.{Engine, EngineConfig} import com.daml.lf.language.LanguageVersion -import com.daml.logging.ContextualizedLogger +import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.logging.LoggingContext.newLoggingContext import com.daml.metrics.MetricsReporting import com.daml.platform.apiserver._ @@ -325,7 +326,8 @@ class Runner(config: SandboxConfig) extends ResourceOwner[Port] { } private def uploadDar(from: File, to: WritePackagesService)(implicit - executionContext: ExecutionContext + executionContext: ExecutionContext, + loggingContext: LoggingContext, ): Future[Unit] = DefaultTelemetry.runFutureInSpan(SpanName.RunnerUploadDar, SpanKind.Internal) { implicit telemetryContext => val submissionId = Ref.SubmissionId.assertFromString(UUID.randomUUID().toString)